Thanks all for attending the first Python Philly CodoDojo meetup! Please review/repeat the Python setup, we would like to make sure that everybody is setup the same way.
Below is a quick overview of what we did and an assignment which we would like you to tackle before the next meetup.
Feel free to reply below with any questions or issues.
Calculator Project
Objective
Create a command line calculator in python. The calculator program should ask the user for mathematical operation (addition, subscription, division and multiplication) and input arguments.
Filename
calculator.py
Run
python calculator.py
Sample output
Please enter mathematical operation (add, sub, mul, div): add Selected: add Please enter first number: 10 Please enter second number: 10 Addition result: 20
Source code
Concepts learned
- Methods/functions
- Command line input
- Flow control (if, elif, else)
Project assignments
Currently, our program quits after its done with the calculation. Modify the program to keep asking the user for operation and operation arguments, after each operation add the result to the total. See sample output and hints below.
For example
(10 + 10) + (100 - 50) = 70
Sample output
Please enter mathematical operation (add, sub, mul, div) or type quit to exit the program: add Selected: add Please enter first number: 10 Please enter second number: 10 Addition result: 20 Total: 20 Please enter mathematical operation (add, sub, mul, div) or type quit to exit the program: sub Selected: sub Please enter first number: 100 Please enter second number: 50 Substruction result: 50 Total: 70 Please enter mathematical operation (add, sub, mul, div) or type quit to exit the program: quit Selected: quit
Hints
- Use a while loop
- You will need to define a variable called "total". Add the individual operation result to total.
- The individual operation methods need to return the result so that it can be added to total
Please let us know if you have any questions