Computer Science

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.

Python

Python Control Flow

56 Likes

Answer

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

Answered By

22 Likes


Related Questions