Question

In: Computer Science

1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...

1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the menu above:  The user will enter the number associated with the selected option. When the user chooses option 1, 2, 3, or 4, your program will prompt the user for two numbers that will be used in the operation. If the user enters 5, your program will quit  The math operations will be as follows: o option 1, add the two numbers o option 2, subtract the second number from the first o option 3, multiply the two numbers o option 4, divide the first number by the second  Print the result of the operation as a floating-point number to the nearest hundredth. For example, if the result is 4, print “4.00”, if the result is 36.45956, print “36.46”  If the user attempts to divide by zero, display a message stating that division by zero is undefined, then display the menu again  After the math operation has been performed and the result displayed, the program should once again display the menu. NOTE: The menu will be displayed continuously until the user selects 5 (quit)  Should the user select an invalid number from the menu (i.e. outside the range 1 – 5), simply display the menu again 3. PYTHON PROGRAM Your program should follow the specification above. It should also include the following:  Use comments on the first few lines to display your name, date, and a brief description of the program  Include a brief comment before each major section of your code  Use meaningful variable names, rather than short names that have no apparent meaning. For example, first_number or selectedOption are good variable names, whereas x and y are not.

This is for python and must run. Thank you!

Solutions

Expert Solution

PYTHON CODE:

loop=1
#while loop until loop==1
while(loop==1):
    
    #menu option
    print("Select Option number:\n(1) addtion\n(2) subtraction\n(3) multiplication\n(4) division\n(5) quit");
    operation=int(input())
    
    #if option is 5 then terminate loop
    if operation==5:
        print("terminated")
        break

    #if option is valid 1 to 5 range then ask for input of 2 values
    if operation>=1 and operation<=5:
        print("Enter first number:")
        x=float(input())
        print("Enter second number:")
        y=float(input())
    
    #if option is 1 perform addtion
    if operation==1:
        r=float(x+y)
        r=round(r,2)     #rounding to 2 decimal place
        print("result:",r)
        
    #if option is 2 perform subtraction
    elif operation==2:
        r=float(x-y)
        r=round(r,2)
        print("result: ",r)
        
    #if option is 3 perform multiplication
    elif operation==3:
        r=float(x*y)
        r=round(r,2)
        print("result: ",r)
        
    #if option is 4 perform division
    elif operation==4:
        r=float(x/y)
        r=round(r,2)
        print("result: ",r)

    

OUTPUT:


Related Solutions

For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
This is an exercise to design and write a Python program in good programming style for...
This is an exercise to design and write a Python program in good programming style for a simulation of stock price over a period of 100 days. In this exercise, you are asked to simulate the stock price starting at $100.00 for 100 days with a daily fluctuation based on the Normal Distribution with mean = 0.0 & sigma = 0.0125. The program will show the daily stock price, the 7-day minimum, the 7-day maximum, the 7-day average, and the...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric input in the correct range, instead of returning an error. Example: Enter your score: 78 Letter...
Building a Command Line Interpreter (myshell) 1.Goal of this programming assignment The primary goal of this...
Building a Command Line Interpreter (myshell) 1.Goal of this programming assignment The primary goal of this assignment is to understand and gain some familiarity with the system call interface in Unix Environment. In this assignment you will be implementing your own command line interpreter like a Unix shell program. YOU ARE NOT IMPLEMENTING COMMANDS! YOUR program should just FORK off programs and EXECUTE them. 2. Requirements (1) Programming language: You have to use either C or C++ to develop your...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to store a date, which includes day(int), month(int), and year(int). 2.Define a structure to store an address, which includes address(house number and street)(string), city(string), state(string), zip code (string). 3.Define a class to store the following information about a student. It should include private member variables: name(string), ID (int), date of birth (the first structure), address (the second structure), total credit earned (int), and GPA (double)....
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then,...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents: Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 8: Assignment 1 # ************************************************* #...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during their candy bar fundraiser using the following data: 12 bars per case. The candy was sold for $1.00 per bar. Each case cost $8.00. They are required to give the student government association 10% of their earnings. The program should ask the user how many bars were sold. The program should calculate and display the SGA proceed's, the Cheer team's proceeds, and the appropriate...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
Programming Assignment No. 5 Write a program that asks the user to enter a positive odd...
Programming Assignment No. 5 Write a program that asks the user to enter a positive odd number less than 20. If the number is 5, 11 or 15, draw a square whose width is the same as the number entered, if 3, 9, or 17, draw a box (a box is a hollowed out square) with the width the same as the number entered, otherwise just present an message saying "To be determined". Write a method for the square that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT