what is the problem in this code ?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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 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: "))
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
Transcribed Image Text: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
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'
Transcribed Image Text: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'
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Map
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education