Question

Write a Python Program that displays repeatedly a menu as shown in the sample run below....

Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the program. All the Tasks has to be defined within functions and named properly for example: addition(number1,number2) for the function that calculates the addition of number 1 and number 2. Define the menu within a function and define also a function that takes as parameters the operation and the two numbers then return the operation result by calling the appropriate defined function or invalid operation otherwise. Make sure to comment your program throughout the code. Requirements: • Appropriate variable and function names • Appropriate Data types and conversions • Correct mathematical calculations • Appropriate functions definitions and calls • Fully commented program. • Correct loop structure • Accurate output display
Sample Run:
Main Menu 1: Addition

2: Subtraction

3: Multiplication

4: Division

5: Exit

Enter a Choice: 1

Enter number 1: 5

Enter number 2: 4

The Answer is: 9

Main Menu

1: Addition

2: Subtraction

3: Multiplication

4: Division

5: Exit

Enter a Choice: 4

Enter number 1: 8

Enter number 2: 2

The Answer is: 4
Main Menu

1: Addition

2: Subtraction

3: Multiplication

4: Division

5: Exit

Enter a Choice: 5

Exiting… Thank you for using the Python Calculator!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#python code

def menu():
    print("Main Menu\n\
            1: Addition\n\
            2: Subtraction\n\
            3: Multiplication\n\
            4: Division\n\
            5: Exit")

def addition(num1, num2):
    return (num1+num2)

def subtraction(num1, num2):
    return (num1- num2)

def multiplication(num1, num2):
    return num1*num2

def division(num1, num2):
    if num2 == 0:
        print("Can not divide by zero..")
    else:
        return num1/num2


if __name__ == "__main__":
    while True:
        menu()
        choice = int(input("Enter a choice: "))
        if choice == 1:
            num1 = int(input("Enter number 1: "))
            num2 = int(input("Enter number 2: "))
            print("The answer is: "+str(addition(num1, num2)))
        elif choice == 2:
            num1 = int(input("Enter number 1: "))
            num2 = int(input("Enter number 2: "))
            print("The answer is: "+str(subtraction(num1, num2)))
        elif choice == 3:
            num1 = int(input("Enter number 1: "))
            num2 = int(input("Enter number 2: "))
            print("The answer is: "+str(multiplication(num1, num2)))
        elif choice == 4:
            num1 = int(input("Enter number 1: "))
            num2 = int(input("Enter number 2: "))
            print("The answer is: "+str(division(num1, num2)))
        elif choice == 5:
            print("Thanks for using this calc App...")
            break
        else:
            print("Wrong choice... please try again..")

#screenshot for indentation help

#output

//If you need any help regarding this solution......... please leave a comment...... Thanks

Add a comment
Know the answer?
Add Answer to:
Write a Python Program that displays repeatedly a menu as shown in the sample run below....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • Read description carefully. Needs to catch exceptions and still be able to keep the program going...

    Read description carefully. Needs to catch exceptions and still be able to keep the program going on past the error. Program should allow user to keep going until he or she quits Math tutor) Write a program that displays a menu as shown in the sample run. You can enter 1, 2. 3, or 4 for choosing an addition. subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • in python and use while loop Exercise: Complete the program that performs basic arithmetic operations of...

    in python and use while loop Exercise: Complete the program that performs basic arithmetic operations of two input numbers. The program displays a menu for user to select a desired operation. ===== MAIN MENU ===== 1. Addition 2. Subtraction 3. Exit Select an operation (1-3): 1 Enter two numbers: 12 20 12 + 20 - 32 - MAIN MENU 1. Addition 2. Subtraction 3. Exit Select an operation (1-3): 2 Enter two numbers: 12 20 12 - 10 = 2...

  • Question 20: Write a python program that will perform the operations of simple calculator. The operations...

    Question 20: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210

  • PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which...

    PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • RAPTOR PROGRAMMING Write a program which will receive two integer values as input. Then prompt the...

    RAPTOR PROGRAMMING Write a program which will receive two integer values as input. Then prompt the user to choose one of the following operations and produce an output with the selected operation. 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division Example output with response: Please enter an input: 2 Please enter another input: 3 Please choose from the follow: 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division Output: 2 % 3 is 2.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT