我尝试使用此代码在摄氏温度和华氏温度之间制作一个简单的温度转换器......我的代码:
value=raw_input("Temperature Reading= ")
check=value[-1]
c=int(value[:-1])
if check =='c' or 'C':
print (9*c/5)+32,'F'
if check =='f' or 'F':
print 5*(c-32)/9,'C'
raw_input("Press <Enter> to exit!")
问题在于,如果用户输入例如 50f,它就会在“if”函数中打印它们。我需要纠正它。谢谢:)
最佳答案
您的支票不正确
if check =='f' or 'F':
应该是
if check == 'f' or check == 'F':
另一个“C”的同上。
更好的是:
if check in ['c', 'C']:
或者
if check.lower() == 'c':
关于python - python中使用OR运算符进行温度转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22793799/