Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: CSCI 195
Views: 5932
Image: ubuntu2004
1
from argparse import ArgumentParser
2
3
parser = ArgumentParser()
4
5
parser.add_argument('--students', required=True, help='A file containing student information')
6
parser.add_argument('--display', nargs='+')
7
8
arguments = parser.parse_args()
9
10
students = list()
11
12
with open(arguments.students) as student_file:
13
for line in student_file:
14
line = line.strip()
15
parts = line.split(",")
16
17
student = dict()
18
student["id"] = int(parts[0])
19
student["first"] = parts[1]
20
student["last"] = parts[2]
21
student["email"] = parts[3]
22
student["homework"] = [87, 91, 84]
23
24
students.append (student)
25
26
if arguments.display:
27
students_to_display = arguments.display
28
else:
29
students_to_display = list()
30
id=int(input('Enter the id of the desired student: '))
31
students_to_display.append(id)
32
33
for id in students_to_display:
34
for student in students:
35
if student['id'] == int(id):
36
print ("{} {} ({})".format(student['first'], student['last'], student['email']))
37
number = 1
38
total = 0
39
for score in student['homework']:
40
print("Homework {}: {}".format(number, score))
41
total += score
42
43
average = total / len (student['homework'])
44
print("\nPercentage: {:.1f}".format(average))
45
break
46
47
48
49
50
51