|
1 | | -# Exercise 03 - Math and Comparisons |
| 1 | +# Exercise 03 - Math, String Operations, and Comparisons |
2 | 2 |
|
3 | 3 | ## Description |
4 | | -Following lesson two on math and comparisons, we will cover essential math skills, some basic string manipulation and comparisons in these tests as well. |
| 4 | +In this exercise, you will build basic RPG combat mechanics to practice working with numbers, string manipulation, and comparison operators. |
5 | 5 |
|
6 | | -Your tasks are described in code comments, but here it is again. **DO NOT** change set values, but replace `None` with how your code should behave. |
| 6 | +## Tasks |
7 | 7 |
|
8 | | -### Run the tests |
9 | | -To run the tests, run the following command in the directory root (`python-excercises`): |
10 | | -```bash |
11 | | -python check.py 03 |
12 | | -``` |
| 8 | +### Task 1: Character Setup |
| 9 | +Define the following variables with their exact values: |
| 10 | +* `player_class` — string set to `"Wizard"` |
| 11 | +* `player_attack` — integer set to `35` |
| 12 | +* `player_defense` — integer set to `13` |
| 13 | +* `enemy_attack` — integer set to `28` |
| 14 | +* `enemy_defense` — integer set to `16` |
| 15 | + |
| 16 | +> **Next step:** Run pytest. If `test_task_1` passes, open your test file and remove the `@pytest.mark.skip` decorator above `test_task_2`. |
| 17 | +
|
| 18 | +### Task 2: Calculate Power Ratings |
| 19 | +* Define `player_attack_power` by multiplying `player_attack` by `player_defense`. |
| 20 | +* Define `enemy_attack_power` by multiplying `enemy_attack` by `enemy_defense`. |
| 21 | + |
| 22 | +> **Next step:** Run pytest. If `test_task_2` passes, open your test file and remove the `@pytest.mark.skip` decorator above `test_task_3`. |
| 23 | +
|
| 24 | +### Task 3: Resolve Damage |
| 25 | +* Define `damage_dealt` by subtracting `enemy_attack_power` from `player_attack_power`. |
| 26 | + |
| 27 | +> **Next step:** Run pytest. If `test_task_3` passes, open your test file and remove the `@pytest.mark.skip` decorator above `test_task_4`. |
| 28 | +
|
| 29 | +### Task 4: Output the Combat Log |
| 30 | +* Define a variable named `combat_log` using an **f-string**. |
| 31 | +* The string must format `player_class` in **ALL CAPS** and insert `damage_dealt`: |
| 32 | + `"WIZARD has suffered 7 damage."` |
| 33 | + |
| 34 | +> **Next step:** Run pytest. If `test_task_4` passes, open your test file and remove the `@pytest.mark.skip` decorator above `test_task_5`. |
| 35 | +
|
| 36 | +### Task 5: Battle Comparisons |
| 37 | +* Define a boolean `is_player_stronger` that checks if `player_attack_power` is greater than `enemy_attack_power`. |
| 38 | +* Define a boolean `is_balanced` that checks if `player_defense` is equal to `enemy_defense`. |
| 39 | + |
| 40 | +> **Next step:** Run pytest. If `test_task_5` passes, open your test file and remove the `@pytest.mark.skip` decorator above `test_task_6`. |
| 41 | +
|
| 42 | +### Task 6: Class Code Extraction |
| 43 | +* Define a variable `class_initial` that extracts the **first letter** of `player_class`. |
| 44 | +* Define a variable `class_code` that extracts the **first 3 letters** of `player_class` in lowercase (e.g., `"wiz"`). |
| 45 | + |
| 46 | +> **Next step:** Run pytest. If `test_task_6` passes, congratulation, you have successfully passed this exercise. |
| 47 | +
|
| 48 | +--- |
13 | 49 |
|
14 | 50 | ## Notes |
15 | | -Learn about math, string operations and comparisons in [TPL lesson](https://thepythonledger.github.io/Docusaurus-engine/lessons/python-foundations/math-strops-and-comparisons). |
| 51 | +Review the concepts covered in this exercise in [The Python Ledger lesson](https://thepythonledger.github.io/Docusaurus-engine/lessons/python-foundations/math-strops-and-comparisons). |
0 commit comments