python - EOFError in Fahrenheit, Celsius, Kelvin Conversion -


i have been trying figure out wrong program i've written convert celsius fahrenheit, fahrenheit celsius, , celsius kelvin. i'm assuming has mixing int , str. may wrong.

def menu():     print("make selection:")     print("\n1. convert celsius fahrenheit")     print("2. convert fahrenheit celsius")     print("3. convert celsius kelvin")     print("4. exit")     choice = int(raw_input("enter choice: "))     return choice  def c(f):     return str((f - 32) / 1.8)  def f(c):     return str((c * 100) + 32)  def k(c):     return str(c + 273.15)   def main():     choice = menu()     while choice != 4:         if choice == 1:             #convert c f             c = eval(raw_input("enter degrees celsius: "))             print(str(c) + "c = " + str(f)) + "f"         elif choice == 2:             #convert f c             f = eval(raw_input("enter degrees fahrenheit: "))             print(str(f) + "f = " + str(c)) + "c"         elif choice == 3:             #convert c k             k = eval(raw_input("enter degrees celsius: "))             print(str(c) + "c = " + str(k)) + "k"         else:             print('invalid entry!')         choice = menu() main() 

my output follows when parsed online:

make selection:  1. convert celsius farenheit 2. convert farenheit celsius 3. convert celsius kelvin 4. exit enter choice: traceback (most recent call last):   line 39, in <module>     main()   line 21, in main     choice = menu()   line 7, in menu     choice = int(raw_input("enter choice: ")) eoferror 

can tell me error is? int & str? raw_input vs input?

rename functions different variables. if conversion functions have same names variables, python 3 give error:

unboundlocalerror: local variable 'f' referenced before assignment 

python interpret letter variable rather function. in addition, have include function argument. changed f(c) function foo(c) , str(f) str(foo(c)) , program worked expected.

note you're missing ending ) on of print() statements. parentheses required print() in python 3.

also note conversion celsius fahrenheit should (c * 1.8) + 32, not (c * 100) + 32.


Comments