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 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...
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 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....
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close Do you...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
You must prompt the user to enter a menu selection. The menu will have the following...
You must prompt the user to enter a menu selection. The menu will have the following selections (NOTE: all menu selections by the user should not be case sensitive): 1. ‘L’ – Length a. Assume that a file containing a series of names is called names.txt and exists on the computer’s disk. Read that file and display the length of each name in the file to the screen. Each name’s middle character or characters should be displayed on a line...
A. Write a C++ with a menu (using switch) that asks the user to select one...
A. Write a C++ with a menu (using switch) that asks the user to select one of the following choices to the user: 1. Options ‘S’ or ‘s’ 2. Option ‘T’ or ‘t 3. Options ‘P’ or ‘p’ 4. print in the Matrix format B. When 1 is selected, prompt the user to enter the starting value st (int value). Use a single FOR loop to count numbers from 1 to st. When the loop is finished, find the average...
Write a C++ code to print to the user a simple menu of a fast food...
Write a C++ code to print to the user a simple menu of a fast food restaurant. You should allow the user to select his/her preferred burgers and/or drinks and you should display the final bill to the user for payment. The user should be able to select more than one item. You should use the switch statement.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT