+ 2

PYTHON caculator

Please help me to solve the problem, it is not running properly after it asks to choose an option. It asks the same thing again and again. THIS IS MY CODE: *********************************************************************************************** name = input("HELLO THERE|\nI AM GOBOT! What is your sweet name: ") question = str(print("Hi " + name + ", welcome to the app. How can I help you.")) print("IT IS A SIMPLE CALCULATOR,BASED ON USER INPUTS.") print("WHAT WOULD YOU LIKE TO DO?") print("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.QUIT") while True: user_input = input("CHOOSE AN OPTION: ") if user_input == 5: print("THANK YOU VISIT AGAIN.") break else: if user_input == 1: a = input(print("enter value of a")) b = input(print("enter value of b")) c = (a + b) print("UNEXPECTED INPUT") else: if user_input == 2: a = input(print("enter value of a")) b = input(print("enter value of b")) c = (a - b) else: if user_input == 3: a = input(print("enter value of a")) b = input(print("enter value of b")) c = (a * b) else: if user_input == 4: a = input(print("enter value of a")) b = input(print("enter value of b")) c = (a / b) else: print("INVALID INPUT") **************************************************************************************************** THIS IS MY RUN OUTPUT: HELLO THERE| I AM GOBOT! What is your sweet name: amu Hi amu, welcome to the app. How can I help you. IT IS A SIMPLE CALCULATOR,BASED ON USER INPUTS. WHAT WOULD YOU LIKE TO DO? 1.Addition 2.Subtraction 3.Multiplication 4.Division 5.QUIT CHOOSE AN OPTION: 1 INVALID INPUT CHOOSE AN

19th May 2019, 11:27 AM
Adarsh Mamgain
Adarsh Mamgain - avatar
3 Answers
+ 3
user_input is a string and you're comparing it to integers. the function input returns string by default. you need to use casting to make it an int. the solution is: user_input = int(input("CHOOSE AN OPTION: ")) instead of user_input = input("CHOOSE AN OPTION: ")
19th May 2019, 11:36 AM
Tomer Sim
Tomer Sim - avatar
+ 5
user_input needs to be converted to an int
19th May 2019, 11:36 AM
Anna
Anna - avatar
+ 3
THANK YOU
19th May 2019, 12:13 PM
Adarsh Mamgain
Adarsh Mamgain - avatar