0
URGENT HELP!!! Please what is wrong with this code?
while True: print("Options: ") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") user_input = input(": ") if user_input == "quit": break elif user_input == "add": ... elif user_input == "subtract": ... elif user_input == "multiply": ... elif user_input == "divide": ... else: print("Unknown input") elif user_input == "add" num1 = float(input ("Enter a number")) num2 = float(input ("Enter a number": ")) result = str (num1 + num2) print("The answer is" + result)
11 Answers
+ 2
First of all, ... is not a code, your code is not finished.
Secondly, you have three quotes in
num2 = float(input ("Enter a number":"))
Should be:
num2 = float(input("Enter a number: "))
Thirdly, you don't have a : here
elif user_input == "add"
code
Should be:
elif user_input == "add":
code
Finally, else can't go before elif.
Here is working, finished code:
https://code.sololearn.com/cQJN7vlpFzSF/?ref=app
0
Thank you very very much, please could you send me other codes you have written so I can study them
0
Also, can you reprogram the above code so that numbers are first initiated? Sorry I'm new to programming. Like 5+3. I used + enter 5 enter 3. I would prefer. 5 enter + enter 3.
0
Give me a sec
0
Ok asman
0
Here you go, calculator as you wished :)
https://code.sololearn.com/cP7iQelYQuGD/?ref=app
All codes, that I write, I post as public, so you can find them in my profile ;)
0
Thank you so much, can you write a code for a quiz app?
0
I'm OK with the calculator, I can explore with that. Thank you sir
0
Can you tell my, quiz app about what?
0
Please, in our chat, not here, not to spam
0
the unknow input should be error