我是python的新手,我被赋予了一个从厘米到英寸的代码,反之亦然。其原理是用户输入一个数字,程序询问他们是否要将其从英寸转换为厘米或厘米到英寸,然后显示结果。在
我在mac上使用Python3.3.5是有帮助的。在
这是我的代码:(注释掉的部分显示了任务和我的第一次尝试)##
##Write a program that converts between centimetres, and inches and vice versa, by:
##asking the user to input a number
##asking the user to choose between converting from centimetres to inches or from inches to centimetres
##calculating and outputting the result using functions
##### Old attempt
##print(" Program to convert beteween centimetres and inches " )
##
##centimetre = 1
##inch = centimetre * 2.45
##
##number = input (" Please enter a number: ")
##choice = input (" Do you want to convert into centimetres or inches: ")
##if choice == "centimetres" or "Centimetres":
## print("Your number is", centimetre*number, "cm")
##else:
## print("Your number is",number*inch, "inches")
number = int(input(" Please enter a number: "))
choice = input(str(" If you want to convert from centimetres to inches type 'A' \n If you want to convert from inches to centimetres type 'B': "))
if choice in "A" or "a":
print(" Your number is" , number*2.54,"inches")
else:
print(" Your number is", number/2.54, "centimetres")
答案已经找到,谢谢你的快速回复!在