Skip to content

Commit f71540e

Browse files
committed
Updated excercise 03
1 parent 2ca2a5a commit f71540e

4 files changed

Lines changed: 78 additions & 103 deletions

File tree

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1 @@
1-
a = 5
2-
b = 10
3-
# Write your code under this comment.
4-
# Do not change the variables a and b as the tests will fail.
5-
6-
# Replace `None` with the correct mathematical operation
7-
## Add a and b
8-
addition = None
9-
## Substract a from b
10-
substraction = None
11-
## Multiply a and b
12-
multiplication = None
13-
## Divide a and b
14-
division = None
15-
16-
17-
# Add these two strings together to variable `concated_name`
18-
f_name = "Jane"
19-
l_name = "Doe"
20-
21-
concat_name = None
22-
23-
24-
# Get some letters from the following string
25-
shop_name = "My Awesome Shop"
26-
## Get the first letter
27-
first_letter = None
28-
## Get the second last letter
29-
second_last_letter = None
30-
31-
32-
# Convert case on the following string
33-
hello = "HeLLo AND WelcomE"
34-
lowercased = None
35-
uppercased = None
36-
titlecased = None
1+
# Write your code here
Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,18 @@
1-
a = 5
2-
b = 10
3-
# Write your code under this comment.
4-
# Do not change the variables a and b as the tests will fail.
1+
player_class = "Wizard"
2+
player_attack = 35
3+
player_defense = 13
4+
enemy_attack = 28
5+
enemy_defense = 16
56

6-
# Replace `None` with the correct mathematical operation
7-
## Add a and b
8-
addition = a + b
9-
## Substract a from b
10-
substraction = a - b
11-
## Multiply a and b
12-
multiplication = a * b
13-
## Divide a and b
14-
division = a / b
7+
player_attack_power = player_attack * player_defense
8+
enemy_attack_power = enemy_attack * enemy_defense
159

16-
# Use f-string to print out the data crunched
17-
# Needs to be in this format:
18-
# A: <a> B: <b> -> +: <addition>, -: <substraction>, *: <multiplication>, /: <division>
19-
formatted_string = f"A: {a} B: {b} -> +: {addition}, -: {substraction}, *: {multiplication}, /: {division}"
20-
print(formatted_string)
10+
damage_dealt = player_attack_power - enemy_attack_power
2111

12+
combat_log = f"{player_class.upper()} has suffered {damage_dealt} damage."
2213

23-
# Add these two strings together to variable `concated_name`
24-
f_name = "Jane"
25-
l_name = "Doe"
14+
is_player_stronger = player_attack_power > enemy_attack_power
15+
is_balanced = player_defense == enemy_defense
2616

27-
concat_name = f_name + l_name
28-
29-
30-
# Get some letters from the following string
31-
shop_name = "My Awesome Shop"
32-
## Get the first letter
33-
first_letter = shop_name[0]
34-
## Get the second last letter
35-
second_last_letter = shop_name[-2]
36-
37-
38-
# Convert case on the following string
39-
hello = "HeLLo AND WelcomE"
40-
lowercased = hello.lower()
41-
uppercased = hello.upper()
42-
titlecased = hello.title()
17+
class_initial = player_class[0]
18+
class_code = player_class[0:3].lower()
Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
def test_basic_math(run_script, expect_variables):
1+
def test_task1(run_script, expect_variables):
22
_, namespace = run_script("math_and_comparisons_solution.py")
33
expect_variables(
44
namespace,
5-
{"addition": 15, "substraction": -5, "multiplication": 50, "division": 0.5},
5+
{
6+
"player_class": "Wizard",
7+
"player_attack": 35,
8+
"player_defense": 13,
9+
"enemy_attack": 28,
10+
"enemy_defense": 16,
11+
},
612
)
713

8-
def test_fstring()
14+
15+
def test_task2(run_script, expect_variables):
16+
_, namespace = run_script("math_and_comparisons_solution.py")
17+
expect_variables(namespace, {"player_attack_power": 455, "enemy_attack_power": 448})
918

1019

11-
def test_string_concat(run_script, expect_variables):
20+
def test_task3(run_script, expect_variables):
1221
_, namespace = run_script("math_and_comparisons_solution.py")
13-
expect_variables(namespace, {"concat_name": "JaneDoe"})
22+
expect_variables(namespace, {"damage_dealt": 7})
1423

1524

16-
def test_string_indexing(run_script, expect_variables):
25+
def test_task4(run_script, expect_variables):
1726
_, namespace = run_script("math_and_comparisons_solution.py")
18-
expect_variables(namespace, {"first_letter": "M", "second_last_letter": "o"})
27+
expect_variables(
28+
namespace,
29+
{"combat_log": "WIZARD has suffered 7 damage."},
30+
)
1931

2032

21-
def test_convert_case(run_script, expect_variables):
22-
TEST_STRING = "HeLLo AND WelcomE"
33+
def test_task5(run_script, expect_variables):
2334
_, namespace = run_script("math_and_comparisons_solution.py")
2435
expect_variables(
2536
namespace,
26-
{
27-
"lowercased": TEST_STRING.lower(),
28-
"uppercased": TEST_STRING.upper(),
29-
"titlecased": TEST_STRING.title(),
30-
},
37+
{"is_player_stronger": True, "is_balanced": False},
38+
)
39+
40+
41+
def test_task6(run_script, expect_variables):
42+
_, namespace = run_script("math_and_comparisons_solution.py")
43+
expect_variables(
44+
namespace,
45+
{"class_initial": "W", "class_code": "wiz"},
3146
)
Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,54 @@
11
import pytest
22

33

4-
def test_basic_math(run_script, expect_variables):
4+
def test_task1(run_script, expect_variables):
55
_, namespace = run_script("math_and_comparisons.py")
66
expect_variables(
77
namespace,
8-
{"addition": 15, "substraction": -5, "multiplication": 50, "division": 0.5},
8+
{
9+
"player_class": "Wizard",
10+
"player_attack": 35,
11+
"player_defense": 13,
12+
"enemy_attack": 28,
13+
"enemy_defense": 16,
14+
},
915
)
1016

1117

12-
@pytest.mark.skip(reason="Finish earlier task first")
13-
def test_string_concat(run_script, expect_variables):
18+
@pytest.mark.skip(reason="Finish task 1 first")
19+
def test_task2(run_script, expect_variables):
1420
_, namespace = run_script("math_and_comparisons.py")
15-
expect_variables(namespace, {"concat_name": "JaneDoe"})
21+
expect_variables(namespace, {"player_attack_power": 455, "enemy_attack_power": 448})
1622

1723

18-
@pytest.mark.skip(reason="Finish earlier task first")
19-
def test_string_indexing(run_script, expect_variables):
24+
@pytest.mark.skip(reason="Finish task 2 first")
25+
def test_task3(run_script, expect_variables):
2026
_, namespace = run_script("math_and_comparisons.py")
21-
expect_variables(namespace, {"first_letter": "M", "second_last_letter": "o"})
27+
expect_variables(namespace, {"damage_dealt": 7})
2228

2329

24-
@pytest.mark.skip(reason="Finish earlier task first")
25-
def test_convert_case(run_script, expect_variables):
26-
TEST_STRING = "HeLLo AND WelcomE"
30+
@pytest.mark.skip(reason="Finish task 3 first")
31+
def test_task4(run_script, expect_variables):
2732
_, namespace = run_script("math_and_comparisons.py")
2833
expect_variables(
2934
namespace,
30-
{
31-
"lowercased": TEST_STRING.lower(),
32-
"uppercased": TEST_STRING.upper(),
33-
"titlecased": TEST_STRING.title(),
34-
},
35+
{"combat_log": "WIZARD has suffered 7 damage."},
36+
)
37+
38+
39+
@pytest.mark.skip(reason="Finish task 4 first")
40+
def test_task5(run_script, expect_variables):
41+
_, namespace = run_script("math_and_comparisons.py")
42+
expect_variables(
43+
namespace,
44+
{"is_player_stronger": True, "is_balanced": False},
45+
)
46+
47+
48+
@pytest.mark.skip(reason="Finish task 5 first")
49+
def test_task6(run_script, expect_variables):
50+
_, namespace = run_script("math_and_comparisons.py")
51+
expect_variables(
52+
namespace,
53+
{"class_initial": "W", "class_code": "wiz"},
3554
)

0 commit comments

Comments
 (0)