Skip to content

Commit b4d08ed

Browse files
committed
Added excercise 03- following math and comparisons lesson
1 parent decbce2 commit b4d08ed

6 files changed

Lines changed: 152 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Exercise 03 - Math and Comparisons
2+
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.
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.
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+
```
13+
14+
## 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).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 = 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
15+
16+
17+
# Add these two strings together to variable `concated_name`
18+
f_name = "Jane"
19+
l_name = "Doe"
20+
21+
concat_name = f_name + l_name
22+
23+
24+
# Get some letters from the following string
25+
shop_name = "My Awesome Shop"
26+
## Get the first letter
27+
first_letter = shop_name[0]
28+
## Get the second last letter
29+
second_last_letter = shop_name[-2]
30+
31+
32+
# Convert case on the following string
33+
hello = "HeLLo AND WelcomE"
34+
lowercased = hello.lower()
35+
uppercased = hello.upper()
36+
titlecased = hello.title()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def test_basic_math(run_script, expect_variables):
2+
_, namespace = run_script("math_and_comparisons_solution.py")
3+
expect_variables(
4+
namespace,
5+
{"addition": 15, "substraction": -5, "multiplication": 50, "division": 0.5},
6+
)
7+
8+
9+
def test_string_concat(run_script, expect_variables):
10+
_, namespace = run_script("math_and_comparisons_solution.py")
11+
expect_variables(namespace, {"concat_name": "JaneDoe"})
12+
13+
14+
def test_string_indexing(run_script, expect_variables):
15+
_, namespace = run_script("math_and_comparisons_solution.py")
16+
expect_variables(namespace, {"first_letter": "M", "second_last_letter": "o"})
17+
18+
19+
def test_convert_case(run_script, expect_variables):
20+
TEST_STRING = "HeLLo AND WelcomE"
21+
_, namespace = run_script("math_and_comparisons_solution.py")
22+
expect_variables(
23+
namespace,
24+
{
25+
"lowercased": TEST_STRING.lower(),
26+
"uppercased": TEST_STRING.upper(),
27+
"titlecased": TEST_STRING.title(),
28+
},
29+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
3+
4+
def test_basic_math(run_script, expect_variables):
5+
_, namespace = run_script("math_and_comparisons_solution.py")
6+
expect_variables(
7+
namespace,
8+
{"addition": 15, "substraction": -5, "multiplication": 50, "division": 0.5},
9+
)
10+
11+
12+
@pytest.mark.skip(reason="Finish earlier task first")
13+
def test_string_concat(run_script, expect_variables):
14+
_, namespace = run_script("math_and_comparisons_solution.py")
15+
expect_variables(namespace, {"concat_name": "JaneDoe"})
16+
17+
18+
@pytest.mark.skip(reason="Finish earlier task first")
19+
def test_string_indexing(run_script, expect_variables):
20+
_, namespace = run_script("math_and_comparisons_solution.py")
21+
expect_variables(namespace, {"first_letter": "M", "second_last_letter": "o"})
22+
23+
24+
@pytest.mark.skip(reason="Finish earlier task first")
25+
def test_convert_case(run_script, expect_variables):
26+
TEST_STRING = "HeLLo AND WelcomE"
27+
_, namespace = run_script("math_and_comparisons_solution.py")
28+
expect_variables(
29+
namespace,
30+
{
31+
"lowercased": TEST_STRING.lower(),
32+
"uppercased": TEST_STRING.upper(),
33+
"titlecased": TEST_STRING.title(),
34+
},
35+
)

‎scripts/new_exercise.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def next_number(category_dir: Path) -> int:
114114

115115

116116
def create_exercise(category_path: str, title: str, style: str) -> None:
117-
category_dir = ROOT / category_path
117+
category_dir = ROOT / "exercises" / category_path
118118
category_dir.mkdir(parents=True, exist_ok=True)
119119

120120
func_name = to_snake_case(title)

0 commit comments

Comments
 (0)