CBSE Class 10 Computer Applications Question 24 of 26

Python Conditionals and Loops — Question 15

Back to all questions
15
Question

Question 11

Write a Python script that asks the user to enter a length in centimetres. If the user enters a negative length, the program should tell the user that the entry is invalid. Otherwise, the program should convert the length to inches and print out the result. There are 2.54 centimetres in an inch.

Answer
Solution
len = int(input("Enter length in cm: "))
if len < 0:
    print("Invalid input")
else:
    inch = len / 2.54
    print(len, "centimetres is equal to", inch, "inches")
Output
Enter length in cm: 150
150 centimetres is equal to 59.05511811023622 inches