Skip to content

Commit e332aa6

Browse files
author
Shehab Abdel-Salam
committed
Add ch4 e15
1 parent 65334eb commit e332aa6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

chapters/chapter04_control_flow/exercises/exercise_ch4_14.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Exercise 04_13 - Reverse Digits
1+
# Exercise 04_14 - Reverse Digits
22
# Write a program that takes an integer as input and returns the integer with its digits reversed.
33
# For example, given the integer 123, the function should return 321.
44

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Exercise 04_15 - GPA Calculator
2+
# Write a program that calculates the GPA of a student.
3+
# The program should take in the grades of the courses and return the GPA of the student.
4+
# For example, given the grades [4, 3, 2], the function should return 3.0.
5+
6+
7+
def gpa_calculator(grades):
8+
# Your code should go here.
9+
10+
return ...

chapters/chapter04_control_flow/tests/test_ch04.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..exercises.exercise_ch4_12 import find_first_divisible_by_5
1313
from ..exercises.exercise_ch4_13 import sum_positive_numbers
1414
from ..exercises.exercise_ch4_14 import reverse_digits
15+
from ..exercises.exercise_ch4_15 import gpa_calculator
1516

1617

1718
def test_ch04_e01():
@@ -107,3 +108,12 @@ def test_ch04_e14():
107108
assert reverse_digits(456) == 654
108109
assert reverse_digits(789) == 987
109110
assert reverse_digits(101) == 101
111+
112+
113+
def test_ch04_e15():
114+
assert gpa_calculator([]) == 0
115+
assert gpa_calculator([4, 3, 2]) == 3.0
116+
assert gpa_calculator([4, 3, 2, 1]) == 2.5
117+
assert gpa_calculator([4, 4, 4, 4]) == 4.0
118+
assert gpa_calculator([3, 3, 3, 3]) == 3.0
119+
assert gpa_calculator([3.2, 3.5, 3.8, 4]) == 3.625

0 commit comments

Comments
 (0)