-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
51 lines (35 loc) · 1013 Bytes
/
functions.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
students = []
def get_students_titlecase():
students_titlecase = []
for student in students:
# must append to students_titlecase
students_titlecase.append(student["name"].title())
return students_titlecase
def print_students_titlecase():
students_titlecase = get_students_titlecase()
print(students_titlecase)
def add_student(name, student_id=332):
student = {"name": name, "student_id": student_id}
students.append(student)
def save_file(student):
try:
# append some text to this file with "a" keyword
f = open("students.txt", "a")
f.write(student + "\n")
f.close()
except Exception:
print("Could not save file")
def read_file():
try:
f = open("students.txt", "r")
for student in f.readlines():
add_student(student)
f.close()
except Exception:
print("Could not read file")
read_file()
print_students_titlecase()
student_name = input("Enter student name: ")
student_id = input("Enter student ID: ")
add_student(student_name, student_id)
save_file(student_name)