Skip to content

Commit 1510543

Browse files
added calculator as exercise 4
1 parent 3b791a8 commit 1510543

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

practice/unit_2/exercise_3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ No [**solution**](solutions/exercise_3_solution.md) provided because this is a 1
5858

5959
---
6060

61-
## [< Exercise 2](exercise_2.md)
61+
## [< Exercise 2](exercise_2.md) | [Exercise 4 >](exercise_4.md)
6262

6363
### [<< Back to Unit 2 Practice](/practice/unit_2/)

practice/unit_2/exercise_4.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# <a id="top"></a>Lab 2 - Simple Calculator
2+
3+
[Back to Syllabus](https://github.com/PdxCodeGuild/Programming102#top)
4+
5+
## 4.1
6+
7+
---
8+
9+
Let's write a simple REPL (read, evaluate, print, loop) calculator that can handle addition and subtraction.
10+
11+
Ask the user for an `operator` and each `operand`. Don't forget that `input` returns a `string`, which you can convert to a float using `float(user_input)` where `user_input` is the string you got from `input`.
12+
13+
Create a separate function for each operation which takes in both `operands` and `returns` the `result` of its operation.
14+
15+
Pass the user's `operands` to the appropriate function based on the user's selected `operator` and use the value the function returns as your `result`.
16+
17+
Below is some sample input/output.
18+
19+
```
20+
> what is the operation you would like to perform? +
21+
> what is the first number? 5
22+
> what is the second number? 7
23+
> 5 + 7 = 12
24+
> what is the operation you would like to perform? done
25+
> goodbye
26+
```
27+
---
28+
## 4.2
29+
30+
Add functionality for multiplication `*` and division `/`
31+
32+
---
33+
## 4.3
34+
35+
Allow the user to have a running total, each command will perform an operation on that number.
36+
37+
```
38+
> what is the starting number? 15
39+
> enter an operation: + 5
40+
> 20
41+
> enter an operation: * 3
42+
> 60
43+
> enter an operation: done
44+
> Your total is 60. Goodbye.
45+
```
46+
47+
### Exercise 4 [solution](solutions/exercise_4_solution.md)
48+
49+
---
50+
51+
## [< Exercise 3](exercise_3.md)
52+
53+
### [<< Back to Unit 2 Practice](/practice/unit_2/)

0 commit comments

Comments
 (0)