Note: Homework assignments should be completed in identified pairs (not more than two students), but may be done individually as well. As a pair, you should submit your assignments separately, but you will receive the same grade as your partner.
In this assignment, you will write a python program that simulates basic calculator functionality.
The user interface of your calculator should ask the user to input a string indicating which mathematical operation to perform, then one or two numbers depending on the calculations. For example:
Enter the operation (+, -, *, /, //, %, abs, or **): *
First number: 5
Second number: 10
Answer: 5 * 10 = 50
Another example:
Enter the operation (+, -, *, /, //, %, abs, or **): //
First number: 10
Second number: 2
Answer: 10 // 2 = 5 with a remainder of 0
A third example:
Enter the operation (+, -, *, /, //, %, abs, or **): %
First number: 90
Answer: 90% = 0.9
Your calculator should support add, subtract, multiply, divide (both float and int with remainder), percent, absolute value, and power (exponentiation) operations.
Your calculator should be able to handle both integers and floats as input. Consider which inputs should be evaluated with the eval
function.
Note: Although %
is used as modulo in Python, for our calculator the user will input %
to mean percent. The user will not be able to request just the modulo of two numbers, but when integer division is requested the remainder will automatically be printed.
The submission:
hmwk2.py
and runs without syntax errorsThe calculator correctly performs the following mathematical operations:
The calculator correctly accepts the user’s input, including:
Your submission must include the course header at the top.
# ------------------------------------------------------
# Name:
# Section: L01, L02, L03, or L04
# Filename: hmwk2.py
# Peers: N/A
# References:
# ------------------------------------------------------
Last Submission February 11, 2020 at 10:00PM (EST). Go to our Moodle page. Submit your hmwk2.py
file and fill out your self-assessment.