Click here to Skip to main content
14,933,227 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#! python3

import os
os.system("cls")


print("please en`enter code here`ter your choice")
print("1.addition\n2.subtraction\n3.multiplication\n4.division")

choice = int(input("please enter your choice"))

number1 = float(input("please enter number one"))
number2 = float(input("please enter number two"))

if(choice == "1"):
    print("%0.2f" %number1, "+", "%0.2f" %number2, "=", (number1 + number2))
elif(choice == "2"):
    print("%0.2f" %number1, "-", "%0.2f" %number2, "=", (number1 - number2))
elif(choice == "3"):
    print("%0.2f" %number1, "*", "%0.2f" %number2, "=", (number1 * number2))
elif(choice == "4"):
        if(number2 != 0):
            print("%0.2f" %number1, "/", "%0.2f" %number2, "=", (number1 / number2))
        else:
            print("The denominator should not be zero to divide")

else:
    print("you have given invalid operator, please try again with a different operator")

----------------------#Below is another short code I tried-----------------------------------

#! python3

import os
os.system("cls")


print("please enter your choice")
print("1.addition\n2.subtraction\n3.multiplication\n4.division")

choice = int(input("please enter your choice"))

number1 = int(input("please enter number one"))
number2 = int(input("please enter number two"))

if(choice == "1"):
    print("the addition is", (number1+number2))
elif(choice == "2"):
    print("the subtraction  is",  (number1-number2))
elif(choice == "3"):
    print("the multiplication is", (number1*number2))
elif(choice == "4"):
        if(number2 !=0):
            print("The division is", (number1 / number2))
        else:
            print("The denominator should not be zero to divide")
else:
    print("you have given incorrect operation number, please try again")


What I have tried:

I have tried indentation and also changing brackets etc but same issue
Posted
Updated 10-Jun-21 4:47am
v2

choice is an integer, you comparing it to a string constant.
Try removing the double quotes in each if and elif condition.
   
Comments
MOHAMMED BILAL NADEEM 10-Jun-21 10:45am
   
Thanks a lot... It worked.. I am new and learning code on my own form home. I do not have anyone to help. You just made my day
OriginalGriff 10-Jun-21 11:03am
   
You're welcome!
choice is an integer. An integer will never be equal to a string. Therefore, choice == "1" can never be true.

Compare the value to an integer instead:
Python
if(choice == 1):
   
Comments
MOHAMMED BILAL NADEEM 10-Jun-21 10:46am
   
Thanks a lot... It worked.. I am new and learning code on my own form home. I do not have anyone to help. You just made my day
Python
if(choice == "1"):

You have declared choice as an integer value, but you are here comparing it to a string.
Change it to a number without the quotes:
Python
if choice == 1:

And do the same with the other tests.
   
Comments
MOHAMMED BILAL NADEEM 10-Jun-21 10:46am
   
Thanks a lot... It worked.. I am new and learning code on my own form home. I do not have anyone to help. You just made my day
Richard MacCutchan 10-Jun-21 10:49am
   
You can find lots of good information at The Python Tutorial — Python 3.7.10 documentation[^].
It worked. Thanks a lot guys. You are my true helpers
   

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