Starting from:

$30

Programming and Computation II Homework 3

CMPSC-132: Programming and Computation II

Homework 3

100 pts
Instructions:
- The work in this assignment must be completed alone.
- The file name must be HW3.py (incorrect name files will get a -10 point deduction)
- When any function returns an error, it must be a string containing “error”
- Do not include test code outside any function in the upload. Remove all your testing code
before uploading your file. That includes user-defined input()
Goal:
Modify the function calculator(expr) so that it supports exponentiation. This operation will be
represented in the string as ^ unlike Python’s **. An example of a valid expression is “-5 + 60 /
3^3 * 4 - 2 * 4 ^2”. In this assignment, more than one consecutive exponentiation is not
supported.
Notes:
- This is a straightforward upgrade of HW2 and there is no starter code
- You will also have to modify findNextOpr and exeOpr to include ^ (which is ** in Python)
- In your submission, include all functions in your HW3.py script (calculator, findNextOpr,
isNumber, getNextNumber and exeOpr)
Function requirements:
 The function must return the computed value if expr is a correct formula, otherwise it must
return an error message.
 When any function returns a numeric value, it must be float
 Do not use exec or eval function. You will not receive credit if your program uses any of the
two functions anywhere
 All five functions from HW2 must work
Grading Notes:
- The grading script will feed 5 randomly chosen test inputs, each for 20 points. One of them
will be an input that should cause an error such as “4 * / 2 + 5 ^”, whose expected returned
value is an error message.
Example:
calculator(“-5 + 60 / 3^3 * 4 - 2 * 4^2”)
-28.11111111111111
calculator("4^2 / 2^2")
4.0
calculator("-4^ / 2^2")
'error'
Deliverables:
 Include all the functions in your script named HW3.py. Submit it to the HW3 CANVAS
assignment before the due date

More products