Skip to content

Commit 7eee190

Browse files
author
Shehab Abdel-Salam
committed
New exercises
1 parent e332aa6 commit 7eee190

File tree

11 files changed

+120
-16
lines changed

11 files changed

+120
-16
lines changed

chapters/chapter01_intro/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# no
21
# This is your playground.
32
# Feel free to experiment with the code under `main()` block and run it as many times as you want.
43
# Try to run `python main.py` in the terminal from the current directory (chapter01_intro).
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Exercise 02_02 - Average Grade
2-
# Write a program that takes three grades (int or float) from a user and calculate the average grade (float).
3-
# The average grade should be **rounded to two decimal places**.
1+
# Exercise 02_02 - Temperature Conversion
2+
# Write a program that converts a temperature from Celsius to Fahrenheit.
3+
# Hint: The formula is: F = C * 9/5 + 32
44

55

6-
def compute_average_grade(grade1, grade2, grade3):
6+
def celsius_to_fahrenheit(celsius):
77
# Your code should go here.
88

99
return ...

chapters/chapter02_variables/exercises/exercise_ch2_04.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Exercise 02_05 - Difference in Length
1+
# Exercise 02_04 - Difference in Length
22
# Write a program that returns the length difference between two words.
33
# For example, given the words "Python" and "Programming", the function should return 3.
44
# Note: The function should return the absolute value of the difference.
5+
# Hint: Can a built-in function help us here?
56

67

78
def compute_length_difference(word1, word2):
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Exercise 02_05 - Temperature Conversion
2-
# Write a program that converts a temperature from Celsius to Fahrenheit.
3-
# Hint: The formula is: F = C * 9/5 + 32
1+
# Exercise 02_05 - Average Grade
2+
# Write a program that takes three grades (int or float) from a user and calculate the average grade (float).
3+
# The average grade should be **rounded to two decimal places**.
44

55

6-
def celsius_to_fahrenheit(celsius):
6+
def compute_average_grade(grade1, grade2, grade3):
77
# Your code should go here.
88

99
return ...

chapters/chapter02_variables/tests/test_ch02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from ..exercises.exercise_ch2_01 import hours_to_seconds
2-
from ..exercises.exercise_ch2_02 import compute_average_grade
2+
from ..exercises.exercise_ch2_02 import celsius_to_fahrenheit
33
from ..exercises.exercise_ch2_03 import add_numbers
44
from ..exercises.exercise_ch2_04 import compute_length_difference
5-
from ..exercises.exercise_ch2_05 import celsius_to_fahrenheit
5+
from ..exercises.exercise_ch2_05 import compute_average_grade
66
from ..exercises.exercise_ch2_06 import convert_binary_to_decimal
77
from ..exercises.exercise_ch2_07 import calculate_gravity_force
88

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
# Exercise 08_05 - File Handler
2-
# Write a custom context manager using a class FileHandler that opens
3-
# and closes a file. Use it to read from data.txt.
1+
# Exercise 08_05 - File Checker
2+
# Check if the numbers in the file are sorted in ascending order.
43

4+
# Example: file1.txt
5+
# 1
6+
# 2
7+
# 3
8+
#
9+
# should return True.
510

6-
class FileHandler: ...
11+
# Example: file2.txt
12+
# 1
13+
# 3
14+
# 2
15+
#
16+
# should return False.
17+
18+
19+
def is_file_sorted(file_name: str) -> bool:
20+
# Your code should go here.
21+
22+
...
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Exercise 08_06 - File Handler
2+
# Write a custom context manager using a class FileHandler that opens
3+
# and closes a file. Use it to read from data.txt.
4+
5+
6+
class FileHandler: ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Exercise 11_05 - Cached Fibonacci
2+
# Given this fibonacci function, we want to cache the results using `functools.lru`.
3+
4+
5+
def compute_fibonacci(n: int) -> int:
6+
# Your code should go here.
7+
8+
...
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Exercise 11_06 - Log This
2+
# Given this "RateInterestCalculator" class with two methods,
3+
# we need to replace the print() messages with log statements instead with
4+
# the appropriate Log Level.
5+
6+
# Can you fix this?
7+
8+
9+
class RateInterestCalculator:
10+
def __init__(self) -> None:
11+
pass
12+
13+
def foo():
14+
print("Info - ...")
15+
...
16+
print("ERROR - something happened")
17+
18+
def bar():
19+
print("Info - ...")
20+
21+
def _baz():
22+
print("debug - ....")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Exercise 11_07 - Parse transaction files
2+
# Given this "RateInterestCalculator" class with two methods,
3+
# we need to replace the print() messages with log statements instead with
4+
# the appropriate Log Level.
5+
6+
# Can you fix this?
7+
8+
from datetime import datetime
9+
10+
11+
class Transaction:
12+
timestamp: str # Replace with `datetime`
13+
description: str
14+
15+
16+
def parse_transactions(filename): ...

0 commit comments

Comments
 (0)