File tree Expand file tree Collapse file tree 2 files changed +119
-0
lines changed Expand file tree Collapse file tree 2 files changed +119
-0
lines changed Original file line number Diff line number Diff line change 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 this week.
5+ # If a student has 8 or more participations, they get an A. If a student has
6+ # between 4 and 7 participations, they get a B. If a student has more than
7+ # 0 but less than 4, the student gets 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 = [
16+ "Sam" ,
17+ "Dan" ,
18+ "Bob" ,
19+ "Dan" ,
20+ "Sam" ,
21+ "Sam" ,
22+ "Bob" ,
23+ "Dan" ,
24+ "Dan" ,
25+ "Ivan" ,
26+ "Ivan" ,
27+ "Ray" ,
28+ "Sam" ,
29+ "Sam" ,
30+ "Dan" ,
31+ "Ivan" ,
32+ "Ivan" ,
33+ "Ray" ,
34+ "Dan" ,
35+ "Ivan" ,
36+ "Ivan" ,
37+ "Sam" ,
38+ "Dan" ,
39+ "Ray" ,
40+ "Sam" ,
41+ "Dan" ,
42+ "Bob" ,
43+ "Dan" ,
44+ "Sam" ,
45+ "Sam" ,
46+ "Dan" ,
47+ "Bob" ,
48+ "Dan" ,
49+ "Sam" ,
50+ "Sam" ,
51+ ]
Original file line number Diff line number Diff line change 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 this week.
5+ # If a student has 8 or more participations, they get an A. If a student has
6+ # between 4 and 7 participations, they get a B. If a student has more than
7+ # 0 but less than 4, the student gets 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 = [
16+ "Sam" ,
17+ "Dan" ,
18+ "Bob" ,
19+ "Dan" ,
20+ "Sam" ,
21+ "Sam" ,
22+ "Bob" ,
23+ "Dan" ,
24+ "Dan" ,
25+ "Ivan" ,
26+ "Ivan" ,
27+ "Ray" ,
28+ "Sam" ,
29+ "Sam" ,
30+ "Dan" ,
31+ "Ivan" ,
32+ "Ivan" ,
33+ "Ray" ,
34+ "Dan" ,
35+ "Ivan" ,
36+ "Ivan" ,
37+ "Sam" ,
38+ "Dan" ,
39+ "Ray" ,
40+ "Sam" ,
41+ "Dan" ,
42+ "Bob" ,
43+ "Dan" ,
44+ "Sam" ,
45+ "Sam" ,
46+ "Dan" ,
47+ "Bob" ,
48+ "Dan" ,
49+ "Sam" ,
50+ "Sam" ,
51+ ]
52+
53+ grade_dict = {}
54+ for student in participation_occurences :
55+ if student not in grade_dict :
56+ grade_dict [student ] = 1
57+ else :
58+ grade_dict [student ] += 1
59+
60+ for student in grade_dict .keys ():
61+ if grade_dict [student ] > 7 :
62+ grade_dict [student ] = "A"
63+ elif grade_dict [student ] > 3 :
64+ grade_dict [student ] = "B"
65+ else :
66+ grade_dict [student ] = "C"
67+
68+ print (grade_dict )
You can’t perform that action at this time.
0 commit comments