Some problems with a code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Some problems with a code

while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'exit' to end the program") input = input(": ") if input == "quit": break elif user_input == "add": num1=int(input("Num1: ")) num2=int(input("Num2: ")) else: print("Unknown input") Need some help here.

17th Nov 2019, 5:26 PM
Vladimir Ivanchenko
Vladimir Ivanchenko - avatar
2 Answers
17th Nov 2019, 5:45 PM
Vladimir Ivanchenko
Vladimir Ivanchenko - avatar
0
In your options, you write "Enter 'exit' to end the program" but in your if statement, the user input that would end the program is "quit", not "exit". You want to make the two consistent. Also, you would want to turn your user input into a float rather than an integer, otherwise you will only be able to add integers properly and any non-integer inputs will give a ValueError. Edit: The code you gave doesn't match the one in the playground...
17th Nov 2019, 8:40 PM
Njeri
Njeri - avatar