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

introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
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...
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 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...
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)....
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program...
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows: BMI = Weight *...
Python Programming 4th edition: Write a program that asks the user for the number of hours...
Python Programming 4th edition: Write a program that asks the user for the number of hours (float) and the pay rate (float) for employee pay role sheet. The program should display the gross pay with overtime if any and without overtime. Hints: Given base_hr as 40 and ovt_multiplier as1.5, calculate the gross pay with and Without overtime. The output should look like as follows: Enter the number of hours worked: Enter the hourly pay rate: The gross pay is $XXX.XX
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT