我试图用python制作一个温度转换计算器。有什么问题有什么帮助吗?我输入了20C
,它告诉我20c=52f
,我知道这是不正确的。这是代码:
def convert(changeto,temp):
if changeto == "c":
converted = (5/9)*(temp-32)
print '%d C = %d F' % (temp,converted)
elif changeto == "f":
converted = (9/5)*(temp+32)
print '%d F = %d C' % (temp, converted)
else:
print "Error, type C or F for Celsius or Fahrenheit conversions."
print "Temperature Converter"
temp = float(raw_input("Enter a temperature: "))
changeto = str(raw_input("Convert to (F)ahrenheit or (C)elsius? "))
convert(changeto,temp)
raw_input("Any key to exit")