Some problems with a code | SoloLearn: Learn to code for FREE!


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.

11/17/2019 5:26:16 PM

Vladimir Ivanchenko

3 Answers

New Answer


It would'be nice if you can copy this code to the plauground and share the link from there. From the text you wrote above, if it's supposed to be a code then a NameError exception would be raised cos "user_input" is not defined. also note, that input is supposed to be a reserved word so avoid using it or simply add a trailing _ input_



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...