Computer Science, asked by ASweety1431, 1 year ago

write a python script that ask the user to enter the length in centimetre if the user internet active 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 .

do it fast !!!!​

Answers

Answered by pragati2901
7

The assignment:

inch = 2.54 #centimeters

is potentially confusing; instead, you could make it clear that it is a ratio:

CM_PER_INCH = 2.54

Note the UPPERCASE_WITH_UNDERSCORES name for a constant, per the style guide.

centimeters = int(input("Enter a number of centimeters"))

There is no reason to limit the user to int input - why not allow float? Then they can enter and convert e.g. 4.2cm.

Also, this will fail with input that can't be converted to an integer (what if the user types seven?) - have a look at this SO community wiki if you want to add validation.

Answered by aum
7

Answer:

inch = 2.54 #centimeters

centimeters = int(input("Enter a number of centimeters"))

print "Entered number of %s centimeters is equal to %s inches" % (centimeters , centimeters / inch)

Explanation:

Similar questions