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.

Grading criteria (16 pts):

Style points (4)

The submission:

  • includes a header including both partners’ names, the filename
  • uses appropriate, informative variable names
  • is called and runs without syntax errors
  • is accompanied by a completed self-evaluation by the author

Operations (8 points)

The calculator correctly performs the following mathematical operations:

  • addition
  • subtraction
  • multiplication
  • division
  • integer division including the remainder
  • percent (divides by 100 and adds a percent sign….see example above)
  • absolute value
  • exponentiation

Inputs (4 points)

The calculator correctly accepts the user’s input, including:

  • successful interpretation of the numeric values as either a float or an int
  • correctly reading the mathematical operation and differentiating between integers and floats when appropriate
  • requests one or two numbers for the user depending on the operation
  • prints an appropriate error message if the user enters an unsupported operation


Your submission must include the course header at the top.

# ------------------------------------------------------
#        Name: 
#     Section: L01, L02, L03, or L04
#    Filename:
#       Peers: N/A
#  References: 
# ------------------------------------------------------

Last Submission February 11, 2020 at 10:00PM (EST). Go to our Moodle page. Submit your file and fill out your self-assessment.