The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 327 Weeks Ago, 4 Days Ago |
| Questions Answered: | 12843 |
| Tutorials Posted: | 12834 |
MBA, Ph.D in Management
Harvard university
Feb-1997 - Aug-2003
Professor
Strayer University
Jan-2007 - Present
Design a simple Command Line Interface (CLI) calculator that performs six (6) basic arithmetic operations: addition, subtraction, multiplication, division, modulo and exponentiation. You shall implement your design in Python and name the file simplecalc.py. It shall work like this:
$ python simplecalc.py
<result>
For example,
$ python simplecalc.py add 5 7
12
Be mindful of implicit type casting and always ensure the accuracy of the program’s operations. You may use the strings “add”, “sub”, “mul”, “div”, “mod” and “exp” to represent the operators. Maintain precision to 3 decimal places where necessary, i.e. 22/7 should result in 3.143.
Include error handling code in your program so that it displays an appropriate message. For instance, in case a user supplies non-numeric operands or if the result is outside of Python’s range (find these limits).
Your program should meet the PEP 8 (pycodestyle) conventions as a minimum. It should also have helpful comments. Write a short one-or-two paragraph description (user manual) of your program in the comments at the beginning of your code.
-----------