-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_health_list.py
67 lines (36 loc) · 1.67 KB
/
student_health_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# ECOR 1042 Lab 3 - Individual submission for student_health_list function
# Remember to include docstring and type annotations for your functions
# Update "" with your name (e.g., Cristina Ruiz Martin)
__author__ = "Kalid Wehbe"
# Update "" with your student number (e.g., 100100100)
__student_number__ = "101259994"
# Update "" with your team (e.g. T-102, use the notation provided in the example)
__team__ = "T-058"
#==========================================#
# Place your student_health_list function after this line
def student_health_list(file_name, health_score):
"""
Puts all the students with the same health score into a list from the excel file
Precondition: excel file == file_name and health_score == type int
Examples:
>>> student_health_list('student-mat.csv', 2)
[ {'School': 'MS', 'Age': 20, 'StudyTime': 1.2, 'Failures': 1, 'Absences': 10,
'G1': 9, 'G2': 11, 'G3': 7}, {another element}, ...]
"""
students = []
with open(file_name, 'r') as f:
lines = f.readlines()
header = lines[0].strip().split(',')
for line in lines[1:]:
row = line.strip().split(',')
if int(row[4]) == health_score:
student = {}
for i in range(len(row)):
if header[i] == "Health":
i = i + 1
else:
student[header[i]] = row[i]
students.append(student)
print(students)
student_health_list('student-mat.csv', 2)
# Do NOT include a main script in your submission