# Fahrenheit to Celcius
def f2c():
userInput = tempEntry.get().lower()
thisEquation = "Fahrenheit to Celcius"
if userInput == "":
textWid.insert(END,"-- " + thisEquation + " --")
textWid.insert(END,"\n")
textWid.insert(END,temp_equations[thisEquation])
textWid.insert(END,"\n")
textWid.insert(END,"\n")
elif userInput.isdigit():
textWid.insert(END,"Fahrenheit = ")
textWid.insert(END,str(((float(userInput) - 32) * (5/9))))
textWid.insert(END,"\n")
else:
textWid.insert(END,"Invalid entry for"+" "+thisEquation)
textWid.insert(END,"\n")
# Fahrenheit to Kelvin
def f2k():
userInput = tempEntry.get().lower()
thisEquation = "Fahrenheit to Kelvin"
if userInput == "":
textWid.insert(END,"-- " + thisEquation + " --")
textWid.insert(END,"\n")
textWid.insert(END,temp_equations[thisEquation])
textWid.insert(END,"\n")
textWid.insert(END,"\n")
elif userInput.isdigit():
textWid.insert(END,"Fahrenheit = ")
textWid.insert(END,str(((5/9)*(float(userInput) - 32) + 273.15)))
textWid.insert(END,"\n")
else:
textWid.insert(END,"Invalid entry for"+" "+thisEquation)
textWid.insert(END,"\n")
userInput是一个全局定义的Tkinter输入框。 我强烈怀疑我的问题源于这两个方程,但我已经多次尝试重新处理它们。在
我的华氏度到摄氏度的转换器总是返回0.0 华氏温度到开尔文的转换器每次大约关闭20度。在
伙计们,如果能帮上忙,我将不胜感激。在
5 / 9
是您的问题:在python2中,用整数除以整数得到一个整数。要使其中至少一个数字成为浮点:
^{pr2}$相关问题 更多 >
编程相关推荐