Skip to content

Commit cafb98c

Browse files
authored
Added participation grade solution
1 parent fd239e6 commit cafb98c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Warning: can be challenging
2+
#
3+
# A teacher is given a list of students. The number of occurences of a student's
4+
# name in the list is the number of times the student participated in this week.
5+
# If a student has more the 7 participation, then got an A. If a student has
6+
# more than 3 but less than 8, the student got a B. If a student has more than
7+
# 0 but less than 4, the student got a C.
8+
#
9+
# Make a dictionary with the keys as the students' name and the values as the
10+
# corresponding student's letter grade. Print the dictionary
11+
#
12+
# Write your code below
13+
14+
15+
participation_occurences = ["Sam", "Dan", "Bob", "Dan", "Sam", "Sam",
16+
"Bob", "Dan", "Dan", "Ivan", "Ivan",
17+
"Ray", "Sam", "Sam", "Dan", "Ivan", "Ivan",
18+
"Ray", "Dan", "Ivan", "Ivan", "Sam", "Dan",
19+
"Ray", "Sam", "Dan", "Bob", "Dan", "Sam",
20+
"Sam", "Dan", "Bob", "Dan", "Sam", "Sam"]
21+
22+
grade_dict = {}
23+
for student in participation_occurences:
24+
if student not in grade_dict:
25+
grade_dict[student] = 1
26+
else:
27+
grade_dict[student] += 1
28+
29+
for student in grade_dict:
30+
if grade_dict[student] > 7:
31+
grade_dict[student] = "A"
32+
elif grade_dict[student] >3:
33+
grade_dict[student] = "B"
34+
else:
35+
grade_dict[student] = "C"
36+
37+
print(grade_dict)

0 commit comments

Comments
 (0)