Having trouble with my Fahrenheit to Celcius/Kelvin converter

math, python, python-2.7

Solution

`5 / 9` is your problem:

>>> 5 / 9
    0

In Python 2, dividing an integer by an integer yields an integer. You want to make at least one of the numbers a float:

>>> 5.0 / 9
    0.5555555555555556
>>> 5.0 / 9.0
    0.5555555555555556

Problem

``` # 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 is a Tkinter Entry box defined globally. I have a strong suspicion that my problem stems from the two equations, but I've tried re-working them many times. My Fahrenheit to Celcius converter always returns 0.0 The Fahrenheit to Kelvin converter is about 20 off every time. Completely stumped here guys, any help would be greatly appreciated.

Original source