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)

31st Oct 2019, 10:43 AM
joshtech2344
joshtech2344 - avatar
11 Respostas
+ 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
31st Oct 2019, 11:08 AM
Asman-H
Asman-H - avatar
0
Thank you very very much, please could you send me other codes you have written so I can study them
31st Oct 2019, 12:16 PM
joshtech2344
joshtech2344 - avatar
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.
31st Oct 2019, 12:18 PM
joshtech2344
joshtech2344 - avatar
0
Give me a sec
31st Oct 2019, 12:24 PM
Asman-H
Asman-H - avatar
0
Ok asman
31st Oct 2019, 12:24 PM
joshtech2344
joshtech2344 - avatar
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 ;)
31st Oct 2019, 12:55 PM
Asman-H
Asman-H - avatar
0
Thank you so much, can you write a code for a quiz app?
31st Oct 2019, 9:10 PM
joshtech2344
joshtech2344 - avatar
0
I'm OK with the calculator, I can explore with that. Thank you sir
31st Oct 2019, 9:11 PM
joshtech2344
joshtech2344 - avatar
0
Can you tell my, quiz app about what?
1st Nov 2019, 3:15 AM
Asman-H
Asman-H - avatar
0
Please, in our chat, not here, not to spam
1st Nov 2019, 3:16 AM
Asman-H
Asman-H - avatar
0
the unknow input should be error
1st Nov 2019, 10:27 PM
Shameke Jones
Shameke Jones - avatar