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
23
students.append (student)
24
25
if arguments.display:
26
students_to_display = arguments.display
27
else:
28
students_to_display = list()
29
id=int(input('Enter the id of the desired student: '))
30
students_to_display.append(id)
31
32
for id in students_to_display:
33
for student in students:
34
if student['id'] == int(id):
35
print ("{} {} ({})".format(student['first'], student['last'], student['email']))
36
break
37
38
39
40
41
42