-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek0 wrap up assignment
197 lines (180 loc) · 5.84 KB
/
Week0 wrap up assignment
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
class Student:
def __init__(self, name, major, andrew_id, gpa):
self.name = name
self.major = major
self.andrew_id = andrew_id
self.gpa = gpa
def update_info(self, major, gpa):
self.major = major
self.gpa = gpa
def __repr__(self):
return self.name + " " + self.major + " " + self.andrew_id + " " + str(self.gpa)
def get_name(self):
return self.name
def get_major(self):
return self.major
def get_andrew_id(self):
return self.andrew_id
def get_gpa(self):
return self.gpa
class course:
def __init__(self, code, name, major, credits):
self.code = code
self.name = name
self.major = major
self.credits = credits
def update_info(self, major, credits, code):
self.major = major
self.credits = credits
self.code = code
def __repr__(self):
return str(self.code) + " " + self.name + " " + self.major + " " + str(self.credits)
def get_name(self):
return self.name
def get_major(self):
return self.major
def get_code(self):
return self.code
def get_credits(self):
return self.credits
#FILE OPENING
f1 = open("students_names.txt", "r+")
f2 = open("courses_names.txt", "r+")
#STUDENT RELATED LIST
Students_list = []
Student_names = []
Student_andrew_id = []
Student_gpa = []
Student_major = []
#COURSE RELATED LIST
Course_list = []
Course_names = []
Course_code_list = []
Course_major = []
Course_credits = []
for line in f1:
line_splitted = line.split("-")
temp_students = Student( line_splitted [0], line_splitted[1], line_splitted[2], float(line_splitted[3].rstrip('\n')))
Students_list.append(temp_students)
for a in Students_list:
Student_names.append(a.get_name())
Student_andrew_id.append(a.get_andrew_id())
Student_gpa.append(a.get_gpa())
Student_major.append(a.get_major())
for line in f2:
line_splitted = line.split(";")
temp_courses = course( line_splitted [0], line_splitted[1], line_splitted[2], float(line_splitted[3].rstrip('\n')))
Course_list.append(temp_courses)
for a in Course_list:
Course_names.append(a.get_name())
Course_code_list.append(a.get_code())
Course_credits.append(a.get_credits())
Course_major.append(a.get_major())
z = len(Student_names)
x = len(Course_list)
version = "v1.0"
#ONLY FOR THE PRESENTATION
print(Student_names)
print(Course_names)
command = input("What do you want?")
while command != "exit":
if command == "show full list":
print(Students_list)
elif command == "show student names":
print(Student_names)
elif command == "check gpa":
n = 0
a1 = input("Which students GPA do you want to check")
while True:
if Student_names[int(n)] == str(a1):
break
else:
n += 1
GPA = float(Student_gpa[int(n)])
if GPA == 0.0:
print("F")
elif GPA > 0.0 and GPA <= 1.0:
print("D")
elif GPA>1.0 and GPA<=2.0:
print("C")
elif GPA >2.0 and GPA <= 3.0:
print("B")
elif GPA >3.0 and GPA <=4.0:
print("A")
elif command == "edit":
n = 0
a1 = input("Which students info do you want to change")
a2 = input("What would be his/her major?")
a3 = input("What would be his/her gpa?")
while True:
if Student_names[int(n)] == str(a1):
break
else:
n += 1
Students_list[int(n)].update_info(str(a2), float(a3))
Student_major[int(n)] = str(a2)
Student_gpa[int(n)] = float(a3)
elif command == "represent":
a1 = input("Which student info do you want to see?")
n = 0
while True:
if Student_names[int(n)] == str(a1):
break
else:
n += 1
print(Students_list[int(n)].__repr__())
#COMMANDS FOR COURSE FILE
elif command == "show courses":
print(Course_list)
elif command == "show course names":
print(Course_names)
elif command == "edit course":
n = 0
a1 = input("Which course info do you want to change")
a2 = input("What would be its 'major' requirement?")
a3 = input("What would be its credit hours?")
a4 = input("What would be its code")
while True:
if Course_names[int(n)] == str(a1):
break
else:
n += 1
Course_list[int(n)].update_info(str(a2), float(a3), str(a4))
Course_major[int(n)] = str(a2)
Course_credits[int(n)] = float(a3)
Course_code_list[int(n)] = str(a4)
elif command == "specific course":
a1 = input("Which specific course info do you want to see?")
n = 0
while True:
if Course_names[int(n)] == str(a1):
break
else:
n += 1
print(Course_list[int(n)].__repr__())
elif command == "summary":
a = open("report.txt", "w")
a.write("Number of students: {}\n".format(z))
a.write("Number of courses: {}\n".format(x))
a.write("Exported using version: {}\n".format(version))
a.close()
elif command == "all s":
print(Student_major)
print(Student_andrew_id)
print(Student_gpa)
print(Student_names)
command = input("OK. What else?")
print("Thank you for using this application")
f1.close()
with open('students_names.txt', "w") as updatedFile:
n = 0
while True:
if n >= z:
break
else:
w1 = Student_names[int(n)]
w2 = Student_major[int(n)]
w3 = Student_andrew_id[int(n)]
w4 = Student_gpa[int(n)]
updatedFile.write("{} {} {} {}\n".format(str(w1), str(w2), str(w3), w4))
n += 1