what is the problem in this code ?
what is the problem in this code ?
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
![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 idlist:
if i = id:
print ("The student record is already in the database!Zero records added")
return
f.close ()
file = open ("data.txt", "a")
name = input ("Enter name: ")
course = input ("Enter course: ")
absences = int (input ("Enter absences: "))
examl = int (input ("Enter exam 1 grade: "))
exam2 = int (input ("Enter exam 2 grade: "))
marks = int (input ("Enter Total Marks: "))
3 = id+" "+name+" "+course+" "+str (absences) +" "+str (examl) +" "+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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F18c50617-8111-4099-9a07-76b22b8ab934%2Ffe9f4fa9-8d5d-4a6f-bd5b-078d3676d387%2Fjjniq5y_processed.png&w=3840&q=75)
![1.Add a student
Any other numeric to terminate
Enter ID:201946530
FileNotFoundError
Traceback (most recent call last)
<ipython-input-1-45aa7e238523> in <module>
choice = int (input ())
30
if choice = 1:
add ()
31
32
---
33
else:
34
break
<ipython-input-1-45aa7e238523> in add ()
1 def add () :
id = input ("Enter ID:")
f = open ("data.txt", "r")
id list = []
lines = f.readlines ()
2
----> 3
4
5
FileNotFoundError:
[Errno 2] No such file or directory: 'data.txt'](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F18c50617-8111-4099-9a07-76b22b8ab934%2Ffe9f4fa9-8d5d-4a6f-bd5b-078d3676d387%2F403894q_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)