python - ValueError when trying to convert strings to floating point -


i'm having troubles running program.
tells me have a

valueerror: not convert string float

the problem though, skips input commands , jumps

print("invalid response") 

this program works fine on cellphone not on windows 10 laptop.

any help? try running , let me know if works you.

def calc():        #the function performing calculation.      if chars == "+":         result = num1 + num2         print (result)         return result     elif chars == "-":         result = num1 - num2         print(result)          return result      elif chars == "*":         result = num1 * num2         print(result)         return result      elif chars == "/":         result = float(num1) / float(num2)         print(result)         return result      else:         print("invalid or unsupported operation")  cont = ""   def contin():         result = calc()         print("operate? y/n: ")         cont = input()   if cont == "y":          print(result)           # output is:                  ought be:         chars = input()                   #result                     result         contin_num = float(input())          calc(contin_num)        #result                     operate y/n         print(result, chars, contin_num)       elif cont == "n":         result = 0         print(result) else:         print ("invalid response.")   num1 = float(input ())  chars = input ()  num2 = float(input ())  result = 0         while num1 > 0 or num2 > 0:      calc()     contin()     break if num1 == 0 , num2 == 0:     print("zero or undefined.") 

this desired code. changed little bit indentations wrong in case of contin() function , logic. please refer if wrong in place tell me. thank you

def calc(num1,chars,num2):        #the function performing calculation.      if chars == "+":         result = num1 + num2         print (result)         return result     elif chars == "-":         result = num1 - num2         print(result)          return result      elif chars == "*":         result = num1 * num2         print(result)         return result      elif chars == "/":         result = float(num1) / float(num2)         print(result)         return result      else:         print("invalid or unsupported operation")  cont = ""   def contin(res):         num1 = res         print("operate? y/n: ")         cont = raw_input()       if cont == "y":              print(num1)           # output is:                  ought be:             chars = raw_input()                   #result                     result             num2 = float(input())              num1=calc(num1,chars,num2)        #result                     operate y/n             print num1           elif cont == "n":             result = 0             print(result)     else:             print ("invalid response.")   num1 = float(input ())  chars = raw_input ()  num2 = float(input ())  result = 0         while num1 > 0 or num2 > 0:      res = calc(num1,chars,num2)     contin(res)     break if num1 == 0 , num2 == 0:     print("zero or undefined.") 

Comments