the-honk/gcse computer science/year 9/python challenges/21 - cm to inch, inch to cm.py

18 lines
437 B
Python
Raw Normal View History

2024-10-09 17:02:27 +00:00
def cmToInch(cm):
return str(cm * 0.393700787) + ' inches'
def inchToCm(inch):
return str(inch * 2.54) + ' cm'
num = int(input('Please input a number.'))
unit = int(input('Would you like to...\n\n1) Convert from centimetres to inches\n2) Convert from inches to centimetres'))
# cm to inch
if unit == 1:
print(cmToInch(num))
# inch to cm
elif unit == 2:
print(inchToCm(num))
else:
print('Invalid input.')
exit()