Question

Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit...

Write a calculator that will give the user this menu options:

1)Add

2)Subtract

3)Multiply

4)Divide

5)Exit

. Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place.

Please answer in python and make it simple. Please implement proper indentation, not just a paragraph of code. Thanks.

Example 1:

Let's calculate!

1) Add

2) Subtract

3) Multiply

4) Divide

5) Exit

Please select one of options above: 4

Enter the first number: 2.81

Enter the second number: 1.111

Answer: 3.1

1) Add

2) Subtract

3) Multiply

4) Divide

5) Exit

Please select one of options above: 5

Have a good day!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
while True:
    print("Let's calculate!")
    print("1) Add")
    print("2) Subtract")
    print("3) Multiply")
    print("4) Divide")
    print("5) Exit")
    choice = int(input("Please select one of options above: "))
    if choice == 5:
        print("Have a good day!")
        break
    n1 = float(input("Enter the first number: "))
    n2 = float(input("Enter the second number: "))
    if choice == 1:
        print("Answer:", n1 + n2)
    elif choice == 2:
        print("Answer:", n1 - n2)
    elif choice == 3:
        print("Answer:", n1 * n2)
    elif choice == 4:
        print("Answer:", n1 / n2)
    else:
        print("Invalid choice!")
Add a comment
Know the answer?
Add Answer to:
Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit...
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
  • Write MIPS code that emulates a simple calculator. The calculator initially has the value 0. Prom...

    Write MIPS code that emulates a simple calculator. The calculator initially has the value 0. Prompt the user to enter a command. A command is a number, where 0 is add, 1 is subtract, 2 is multiply, 3 is divide, 4 is clear, and 5 is exit. When the user enters 0, 1, 2, or 3, prompt the user for a number to add, subtract, multiply or divide from the current value. If the user enters 4, then clear the...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • IN PYTHON! Create a calculator GUI. The GUI should let the user add, subtract, multiply, and...

    IN PYTHON! Create a calculator GUI. The GUI should let the user add, subtract, multiply, and divide two numbers they input. All user input and the result displayed to the user should be seen in the GUI itself (i.e. the terminal should not show anything). Thank you very much! PLEASE PASTE IN HERE THE RIGHT INDENTS

  • Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two...

    Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two numbers. You can use whatever format you want to receive the numbers (such as textboxes). You also can use whatever method (such as a button for each operation +, -, *, /) to determine what operation the user wants to accomplish. The output should be displayed in a similar format to "1 + 2 = 3" or "1 - 2 = -1". Make sure...

  • 1.Write a Python program to perform simple arithmetic operations (add, subtract, multiply and divide) on 2...

    1.Write a Python program to perform simple arithmetic operations (add, subtract, multiply and divide) on 2 numbers and display the output on console     ( use methods in your program) Range of numbers : 1 to 100 (Do not use 0)

  • 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...

  • Could you code this question on Matlab? :) Question: Design a GUI based application, named Calculator, which perform basic arithmetic operations ie., add, subtract, multiply, and divide Your design m...

    Could you code this question on Matlab? :) Question: Design a GUI based application, named Calculator, which perform basic arithmetic operations ie., add, subtract, multiply, and divide Your design must have 1) Two separate input fields for reading the two operands (let's say a and b) 2) 4 Four button (labeled as +, -, *, /) to let the user select an operation. 3) An output field for displaying the result Following table shows operations performed on pushing each of...

  • Can somebody help me with this assignment. I will highly appreciate. Also, please display the output...

    Can somebody help me with this assignment. I will highly appreciate. Also, please display the output as well. I need to use JAVA to to write the program. This is the sample output provided by my professor. HOME WORK: due 09.17.2019 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

  • home work

    a.      You must use proper error and exception handling (try, catch) in the application. [5 marks] b.      Accept the users first and last name store in two SEPARATE variables. [2 marks] c.      Accept two numbers:                                i.     validate that the user has entered numbers for each input. [3 marks]                               ii.     For invalid numbers ask the user to re-enter the number [2 marks]                               iii.     If the user enters a number greater than 500 throw an exception, display a message that numbers should...

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