Question

In: Computer Science

In Python, write a calculator that will give the user the following menu options: 1) Add...

In Python, write a calculator that will give the user the following 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.

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: 2.5

 

1) Add

 

2) Subtract

 

3) Multiply

 

4) Divide

 

5) Exit

 

Please select one of options above: 5

 

Have a good day!

Solutions

Expert Solution

Program:

print("\nLet's calculate!")

while(True):
   print("\n1) Add")
   print("2) Subtract")
   print("3) Multiply")
   print("4) Divide")
   print("5) Exit")
   option=int(input("\nPlease select one of options above: "))
  
   if(option==1):
       no1=float(input("Enter the first number: "))
       no2=float(input("Enter the second number: "))
       print("Answer: %.1f"%(no1+no2))
   elif(option==2):
       no1=float(input("Enter the first number: "))
       no2=float(input("Enter the second number: "))
       print("Answer: %.1f"%(no1-no2))
   elif(option==3):
       no1=float(input("Enter the first number: "))
       no2=float(input("Enter the second number: "))
       print("Answer: %.1f"%(no1*no2))
   elif(option==4):
       no1=float(input("Enter the first number: "))
       no2=float(input("Enter the second number: "))
       print("Answer: %.1f"%(no1/no2))
   elif(option==5):
       print("Have a good day!\n")
       break
   else:
       print("Invalid option!!\n")

Program Screenshot:

Output:


Related Solutions

Write a python program to display a menu with the following options: (1) add, (2) subtract,...
Write a python program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. I f 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.
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide...
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide Power Root Modulus Upon receiving the user's selection, prompt the user for two numeric values and print the corresponding solution based on the user's menu selection. Ask the user if they would like to use the calculator again. If yes, display the calculator menu. otherwise exit the program. EXAMPLE PROGRAM EXECUTION: Add Subtract Multiply Divide Power Root Modulus Please enter the number of the...
in python This is the animal speaking game. Print the following menu for your user: ------------------------------------...
in python This is the animal speaking game. Print the following menu for your user: ------------------------------------ 1) Dog 2) Cat 3) Lion 4) Sheep 5) Exit Please enter a selection. ------------------------------------ If the user enters 1, print("Bark") If the user enters 2, print("Meow") If the user enters 3, print("Roar") If the user enters 4, print("Baah") If the user enters 5, exit the program. define functions for each animal. For example: def dog() : def cat() : and so forth ......
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle    3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle then display it's area using the following formula: area = PIr2 Use 3,14159 for PI and the radius of the circle for r. If the...
Add the result envidented by the python compiler. use python language. 1(a) A Give the output...
Add the result envidented by the python compiler. use python language. 1(a) A Give the output for the array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729]) a. a[:6:2] = -1000 (ii) a[ : :-1] ) b. Display the values of 1D array using for loop?
 c. Write a code to print a 3D array?
 d. How to print the transpose of a 2D array?
 e Write a function to sort the array row and coloumn wise ?...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
C++ Write a menu based program for the pet rescue. There should be 2 menu options...
C++ Write a menu based program for the pet rescue. There should be 2 menu options -Add a pet -View pets -If the user chooses option 1, you will open a data file for writing without erasing the current contents, and write a new pet record to it. The file can be formatted any way that you choose but should include the pet's name, species, breed, and color. You my also include any additional information you think is appropriate. -If...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT