Skip to content

Commit 8330f3f

Browse files
committed
Add main function to test count_magical
1 parent 151377c commit 8330f3f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

2_intermediate/chapter11/practice/count_magical.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
# if the number of evens is greater than
55
# half of the length of the list, print "Magical"
66
# Else, print "Not Magical"
7+
#
8+
# Write a function called main which tests
9+
# the count_magical function on at least
10+
# 3 different lists of integers. Use the main
11+
# function to test count_magical by calling main().
712

813
# write code here

2_intermediate/chapter11/solutions/count_magical.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# if the number of evens is greater than
55
# half of the length of the list, print "Magical"
66
# Else, print "Not Magical"
7+
#
8+
# Write a function called main which tests
9+
# the count_magical function on at least
10+
# 3 different lists of integers. Use the main
11+
# function to test count_magical by calling main().
712

813
def count_magical(my_list):
914
number_of_evens = 0
@@ -17,3 +22,16 @@ def count_magical(my_list):
1722
print("Not Magical")
1823

1924
return number_of_evens
25+
26+
27+
def main():
28+
list_1 = [1, 2, 3, 4, 5, 6] # not magical, 3 evens
29+
list_2 = [0, 35, 1, 35, 2, 4] # not magical, 3 evens
30+
list_3 = [10, 20, 12, 3, -9] # magical, 3 evens
31+
32+
print("Number of evens in list 1:", count_magical(list_1))
33+
print("Number of evens in list 2:", count_magical(list_2))
34+
print("Number of evens in list 3:", count_magical(list_3))
35+
36+
37+
main()

0 commit comments

Comments
 (0)