0

what is wrong with my user_input line? practice calc

while True: print ("options:") print ("Enter 'add' to add two numbers:") print ("Enter 'sub' to subtract two numbers:") print ("Enter 'mult' to multiply two numbers:") print ("Enter 'div' to divide two numbers:") print ("Enter 'quit' to end program:") user_input = input(":") if user_input == "quit": break elif user_input == "add": num1 = (float("Enter a number:")) num2 = (float("Enter the second number:")) result = str(num1 + num2) print ("The answer is" + result) elif user_input == "sub": num1 = (float("Enter a number:")) num2 = (float("Enter the second number:")) result = str(num1 - num2) print("The answer is" + result) elif user_input == "mult": num1 = (float("Enter a number:")) num2 = (float("Enter the second number:")) result = str(num1 * num2) print("The answer is" + result) elif user_input == "div": num1 = (float("Enter a number:")) num2 = (float("Enter the second number:")) result = str(num1 / num2) print("The answer is" + result) line 8 user_input = input(":") is giving me grief in code playground

25th Jul 2016, 12:27 PM
lite
2 Réponses
0
There is a more dire problem. You are trying to convert strings into floats. 乁ʕ •̀ ۝ •́ ʔㄏ I assume you forgot the input(). This calculator would not work in the code playground. You must run it on the python on your computer or QPython 3 for android.
25th Jul 2016, 12:49 PM
Gershon Fosu
Gershon Fosu - avatar
0
Thank you. I am investigating the strings into floats issue, but as I'm a brand new baby, I'm not doing well.
25th Jul 2016, 2:56 PM
lite