Question

Write a phython program to display a menu with the following options: (1) add, (2) subtract,...

Write a phython program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. If the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.

Homework Answers

Answer #1

Solution

code

# This function finds the addition of two numbers
def add(x, y):
return x + y
# This function finds the subtraction of two numbers
def subtract(x, y):
return x - y
# This function finds the multiplication of two numbers
def multiply(x, y):
return x * y
# This function finds the division of two numbers
def divide(x, y):
return x / y
# This function finds the mod of two numbers
def mod(x, y):
return x % y
# This function do nothing
def donothing(x,y):
return null
print("Select operation.")
print("(1) add")
print("(2) subtract")
print("(3) multiply")
print("(4) Divide")
print("(5) mod")
print("(6) do nothing")
# Take input from the user
choice = input("Please enter choice(1/2/3/4/5/6):")
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
elif choice == '5':
print(num1,"%",num2,"=", mod(num1,num2))
elif choice == '6':
print("Do nothing")
else:
print("Error :Invalid input")

Screenshot

Output

--

all the best

please upvote

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
Write a python program that functions as a calculator. The program should run in an infinite...
Write a python program that functions as a calculator. The program should run in an infinite loop. It should ask the user for two numbers and then offer four choices: 1) Add 2) Subtract 3) Multiply 4) Divide Once it gets the operation from the user, it should call one of four functions to perform the operation and display the result. The functions should be placed in another module called calc.py
I would like you to do is create a console application that will either add, subtract...
I would like you to do is create a console application that will either add, subtract or divide two numbers. The Program will have four functions one to add, subtract, multiply and divide the two numbers. The user will enter the two number and the +, -, *, / symbol and the program will display the appropriate result.
Write a java 3x3 matrix program that does the following: 1) multiply 2)add 3)subtract 4)scalar product...
Write a java 3x3 matrix program that does the following: 1) multiply 2)add 3)subtract 4)scalar product 5)does calculation for a^3 - b^3 6)does calculation for 2a^ + 3b^2 an example for the adding method will look something like this public static double[][] multiplyMatrix(double [][] a, double [][] b)
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player position 6 – Edit player stats 7 - Exit program POSITIONS C, 1B, 2B, 3B, SS, LF, CF, RF, P Team data file could not be found. You can create a new one if you want. ================================================================ Menu option: 2 Name: Mike Position: SS At bats: 0 Hits: 0 Mike was added....
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write a menu-driven program for  Food Court. (You need to use functions!) Display the food menu to a user . 5 options Use numbers for the options and for example "6" to exit. Ask the user what he/she wants and how many of it. (Check the user inputs) AND use strip() function to strip your inputs(if needed) Keep asking the user until he/she chooses the exit...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
Write a program that asks the user for three integers (firstInt, secondInt, thirdInt). Perform the following...
Write a program that asks the user for three integers (firstInt, secondInt, thirdInt). Perform the following operations and output the results: firstResult = Add firstInt and secondInt then divide the result by thirdInt secondResult = Multiply secondInt by thirdInt and divide result by the sum of secondInt and firstInt thirdResult = Multiply firstInt by thirdInt and find the remainder of dividing the result by secondInt Your prompts to the user to enter the integers must be: Enter firstInt: Enter secondInt:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT