Starting from:

$29.99

COP3502 Lab 02: One-Run Calculator Solution



Overview
In this lab, students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input. The program will then display the result of the operation and exit. The project is designed to give students an opportunity to practice input, output, selection, and basic operators via a simple program.

Specification

When the program starts it should prompt the user to enter an operand and read a floating point number as follows:

Enter first operand: 89.1
Enter second operand: 42

Once the two operands have been read and stored, the program should display a menu as follows:

Calculator Menu
---------------
1. Addition
2. Subtraction
3. Multiplication
4. Division

…and then display a menu and accept user input (we recommend an integer type for the input):

Which operation do you want to perform? 1

If a valid operation is selected, the program should print the result and exit:

The result of the operation is 131.1. Goodbye!

If the input is an invalid integer, it should print this error message and exit:

Error: Invalid selection! Terminating program.
Submissions
NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission!

File: calculator.py
Method: Submit on ZyLabs

Do not submit any other files!

Sample Output

Example #1
⎯⎯⎯⎯⎯⎯⎯
Enter first operand: 2.25
Enter second operand: -1.5

Calculator Menu
---------------
1. Addition
2. Subtraction
3. Multiplication
4. Division

Which operation do you want to perform? 4

The result of the operation is -1.5. Goodbye!

Example #2
⎯⎯⎯⎯⎯⎯⎯
Enter first operand: 30.9
Enter second operand: 86.75

Calculator Menu
---------------
1. Addition
2. Subtraction
3. Multiplication
4. Division

Which operation do you want to perform? 100

Error: Invalid selection! Terminating program.

More products