Python新手-尝试将厘米编码为英寸,反之亦然

Python新手-尝试将厘米编码为英寸,反之亦然,python,Python,我是python新手,我的任务是编写厘米到英寸的代码,反之亦然。这个想法是用户输入一个数字,程序询问他们是想把它从英寸转换成厘米还是厘米转换成英寸,然后显示结果 我在mac上使用Python3.3.5,这很有帮助 这是我的代码:(注释掉的部分显示了任务和我的第一次尝试) 已找到答案,感谢您的快速回复 应将条件if choice in“A”或“A”:修改为,例如,if choice in“Aa”:以便测试选项是“A”还是“A”。原始版本的计算结果总是True您必须执行如果在(“A”、“A”)中选择

我是python新手,我的任务是编写厘米到英寸的代码,反之亦然。这个想法是用户输入一个数字,程序询问他们是想把它从英寸转换成厘米还是厘米转换成英寸,然后显示结果

我在mac上使用Python3.3.5,这很有帮助

这是我的代码:(注释掉的部分显示了任务和我的第一次尝试)


已找到答案,感谢您的快速回复

应将条件
if choice in“A”或“A”:
修改为,例如,
if choice in“Aa”:
以便测试选项是“A”还是“A”。原始版本的计算结果总是
True

您必须执行
如果在(“A”、“A”)
中选择了一些提示,您可能希望使用
浮点值来转换输入数字,而不是
int
,因为int只知道如何解释整数值,而浮点值可以处理小数。您也不必将引号中的任何内容转换为字符串。它已经是一个字符串了。这适用于
choice=input(str(“…
@IsabelSecord忽略我的答案(现已删除),你的打印效果很好,我实际上没有意识到打印可以像你那样使用。我不同意分配给的重复标志。我只是阅读了它,两者之间没有任何联系。是的,这是答案谢谢!这似乎让我的python代码工作起来了!谢谢你的快速回复!
##
##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")