Question: For the below code (Python), I keep getting an operation error when I try to choose the operation. How do I fix this in my
For the below code (Python), I keep getting an operation error when I try to choose the operation. How do I fix this in my code?
#Print the welcome message and menu list print("Welcome to the Python Calculator Application.") print("What calculation do you want to perform? ") print("1) Addition (+)") print("2) Subtraction (-)") print("3) Division (/)") print("4) Multiplication (*)") print("5) Modulus (%)") #Take user choice userChoice = input("Enter 1,2,3,4 or 5 indicating your selection.") #Check if user choice is addition if(userChoice == "1"): print("Addition was selected.") first = int(input("Enter your first integer:")) second = int(input("Enter your second integer:")) print("Addition of "+str(first)+" and "+str(second)+" is : "+str(first+second)) #Check if user choice is Subtraction elif(userChoice=="2"): print("Subtraction was selected.") first = int(input("Enter your first integer:")) second = int(input("Enter your second integer:")) print("Difference of "+str(first)+" and "+str(second)+" is : "+str(first-second)) #Check if user choice is division elif(userChoice=="3"): print("Division was selected.") first = int(input("Enter your first integer:")) second = int(input("Enter your second integer:")) print("Division of "+str(first)+" and "+str(second)+" is : "+str(first/second)) #Check if user choice is multiplication elif(userChoice=="4"): print("Multiplication was selected.") first = int(input("Enter your first integer:")) second = int(input("Enter your second integer:")) print("Multiplication of "+str(first)+" and "+str(second)+" is : "+str(first*second)) #Check if user choice is modulus elif(userChoice=="5"): print("Modulus was selected.") first = int(input("Enter your first integer:")) second = int(input("Enter your second integer:")) print("Modulus of "+str(first)+" and "+str(second)+" is : "+str(first%second)) #If option is invalid else: print("Invalid Operation")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
