CBSE Class 11 Computer Science
Question 124 of 161
Flow of Control — Question 1
Back to all questions 1
Question Question 1
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.
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