I'm having troubles running this program.
It tells me I have a
ValueError: could not convert string to float
The problem is though, that it just skips my input commands and jumps to
print("Invalid Response")
This program works fine on my cellphone but not on my windows 10 laptop.
Any help? Try running it and let me know if it works for 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 to 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 and num2 == 0:
print("Zero or undefined.")
elif's have a different indentation than theif, and they also have less indentation than the rest of the code in the function. Fix the indentation then try again.calc()to end so it would be difficult for me to do the corrections. The usual way to post code is to copy-and-paste from your text file, highlight the code with your mouse or keyboard, then click the "code sample" icon (which looks like a pair of braces) in the question editor. This will easily add the four spaces to each line.