need you to add this feature to the code down below, please def add(): id = input("Enter ID:") f = open("data.txt", "r") id_list = [] lines = f.readlines() if lines != "": for line in lines: token = line.split(" ") id_list.append(token[0]) for i in id_list: if i == id: print("The stude
hi I need you to add this feature to the code down below, please
def add():
id = input("Enter ID:")
f = open("data.txt", "r")
id_list = []
lines = f.readlines()
if lines != "":
for line in lines:
token = line.split(" ")
id_list.append(token[0])
for i in id_list:
if i == id:
print("The student record is already in the
return
f.close()
file = open("data.txt", "a")
name = input("Enter name: ")
course = input("Enter course: ")
absences = int(input("Enter absences: "))
exam1 = int(input("Enter exam 1 grade: "))
exam2 = int(input("Enter exam 2 grade: "))
marks = int(input("Enter Total Marks: "))
s = id+" "+name+" "+course+" "+str(absences)+" "+str(exam1)+" "+str(exam2)+" "+str(marks)+"\n"
file.write(s)
file.close()
while True:
print("1.Add a student")
print("Any other numeric to terminate")
choice = int(input())
if choice == 1:
add()
else:
break
Step by step
Solved in 2 steps