Python Program to Perform Arithmetic Operation Based on User Choice
print("1. for Addition")
print("2. for subtraction")
print("3. for Division")
print("4. for multiplication")
print("5. for modulo")
number1=int(input("Enter first number:"))
number2=int(input("Enter second number:"))
choice=int(input("Enter your choice to perfo+rm operation"))
if choice==1:
add=number1+number2
print(f"The addition of {number1} and {number2} is {add}")
#print("The addition of number1 and number2 is",add)
elif choice==2:
sub=number1-number2
print(f"The subtraction of {number1} and {number2} is {sub}")
elif choice==3:
div=number1/number2
print(f"The division of {number1} and {number2} is {div}")
elif choice==4:
mult=number1*number2
print(f"The multiplication of {number1} and {number2} is {mult}")
elif choice==5:
modulo=number1%number2
print(f"The remainder of {number1} and {number2} division is {modulo}")
else:
print("Your choice is invalid! Please enter your choice in 1,2,3,4,5")
Output:
1. for Addition
2. for subtraction
3. for Division
4. for multiplication
5. for modulo
Enter first number:20
Enter second number:20
Enter your choice to perfo+rm operation1
The addition of 20 and 20 is 40
Another Program By Using Character as User Choice
print("+. for Addition")
print("-. for subtraction")
print("/. for Division")
print("*. for multiplication")
print("%. for modulo")
number1=int(input("Enter first number:"))
number2=int(input("Enter second number:"))
choice=(input("Enter your choice to perform operation"))
if choice=='+':
add=number1+number2
print(f"The addition of {number1} and {number2} is {add}")
#print("The addition of number1 and number2 is",add)
elif choice== '-':
sub=number1-number2
print(f"The subtraction of {number1} and {number2} is {sub}")
elif choice=='/':
div=number1/number2
print(f"The division of {number1} and {number2} is {div}")
elif choice=='*':
mult=number1*number2
print(f"The multiplication of {number1} and {number2} is {mult}")
elif choice=='%':
modulo=number1%number2
print(f"The remainder of {number1} and {number2} division is {modulo}")
else:
print("Your choice is invalid! Please enter your choice in 1,2,3,4,5")
Output:
+. for Addition
-. for subtraction
/. for Division
*. for multiplication
%. for modulo
Enter first number:20
Enter second number:20
Enter your choice to perform operation+
The addition of 20 and 20 is 40
0 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏