Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
print("select the operation you want to perform :")
print(" 1 for add")
print(" 2 for subtract")
print(" 3 for multiply")
print(" 4 for divide")
choice = input("select the number you want for operation")
x = int(input("first number for operation"))
n = int(input("second number for operation"))
if choice == 1:
print(int(x) + int(n))
if choice == 2:
print(x - n )
if choice == 3:
print(x * n)
if choice == 4:
print(x / n)

What I have tried:

I have tried to make a small type of calculator . but it is not printing the answer
I have googled it and also asked my bunch of friends but no one is able to solve my query
Posted
Updated 21-Mar-18 5:05am

1 solution

Your choice variable is of type string but you are comparing it with integer literals.

So either make it an int:
Python
choice = int(input("select the number you want for operation"))
or perform string comparisons:
Python
if choice == "1":
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900