hi i keep geting an erorr when i want to view the information import csv # Define global variables student_fields = [ 'ID', 'name', 'courses', 'absences', 'm1', 'm2', 'm3', 'total' ] student_database = 'students.csv' def display_menu(): print("--------------------------------------") print(" Welcome to Student Management System") print("---------------------------------------") print("1. Add New Student") print("2. View Students") print("3. Search Student by iD") print("4. Search Student by courses") print("5. Delete Student") print("6. Quit") def add_student(): print("-------------------------") print("Add Student Information") print("-------------------------") global student_fields global student_database student_data = [] for field in student_fields: value = input("Enter " + field + ": ") student_data.append(value) with open(student_database, "a", encoding="utf-8") as f: writer = csv.writer(f) writer.writerows([student_data]) print("Data saved successfully") input("Press any key to continue") return def view_students(): global student_fields global student_database print("--- Student Records ---") with open(student_database, "r", encoding="utf-8") as f: reader = csv.reader(f) for x in student_fields: print(x, end='\t |') print( "\n-----------------------------------------------------------------" ) for row in reader: for item in row: print(item, end="\t |") print("\t ") input("Press any key to continue") def search_student_ID(): global student_fields global student_database print("--- Search Student ---") ID = input("Enter ID no. to search: ") with open(student_database, "r", encoding="utf-8") as f: reader = csv.reader(f) for row in reader: if len(row) > 0: if ID == row[0]: print("----- Student Found -----") print("ID: ", row[0]) print("Name: ", row[1]) print("courses: ", row[2]) print("absences: ", row[3]) print("m1: ", row[4]) print("m2: ", row[5]) print("m3: ", row[6]) print("total: ", row[7]) break else: print("ID not found in our database") input("Press any key to continue") def search_student_courses(): global student_fields global student_database print("--- Search Student by courses ---") courses = input("Enter course to search: ") with open(student_database, "r", encoding="utf-8") as f: reader = csv.reader(f) for row in reader: if len(row) > 2: if courses == row[2]: print("----- Student Found -----") print("ID: ", row[0]) print("Name: ", row[1]) print("courses: ", row[2]) print("absences: ", row[3]) print("m1: ", row[4]) print("m2: ", row[5]) print("m3: ", row[6]) print("total: ", row[7]) break else: print("courses not found in our database") input("Press any key to continue") def delete_student(): global student_fields global student_database print("--- Delete Student ---") ID = input("Enter ID. to delete: ") student_found = False updated_data = [] with open(student_database, "r", encoding="utf-8") as f: reader = csv.reader(f) counter = 0 for row in reader: if len(row) > 0: if ID != row[0]: updated_data.append(row) counter += 1 else: student_found = True if student_found is True: with open(student_database, "w", encoding="utf-8") as f: writer = csv.writer(f) writer.writerows(updated_data) print("ID ", ID, "deleted successfully") else: print("ID not found in our database") input("Press any key to continue") while True: display_menu() choice = input("Enter your choice: ") if choice == '1': add_student() elif choice == '2': view_students() elif choice == '3': search_student_ID() elif choice == '4': search_student_courses() elif choice == '5': delete_student() else: break print("-------------------------------") print(" Thank you for using our system") print("-------------------------------")

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

hi i keep geting an erorr when i want to view the information

 


import csv
# Define global variables
student_fields = [
'ID', 'name', 'courses', 'absences', 'm1', 'm2', 'm3', 'total'
]
student_database = 'students.csv'


def display_menu():
print("--------------------------------------")
print(" Welcome to Student Management System")
print("---------------------------------------")
print("1. Add New Student")
print("2. View Students")
print("3. Search Student by iD")
print("4. Search Student by courses")
print("5. Delete Student")
print("6. Quit")


def add_student():
print("-------------------------")
print("Add Student Information")
print("-------------------------")
global student_fields
global student_database

student_data = []
for field in student_fields:
value = input("Enter " + field + ": ")
student_data.append(value)

with open(student_database, "a", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows([student_data])

print("Data saved successfully")
input("Press any key to continue")
return


def view_students():
global student_fields
global student_database

print("--- Student Records ---")

with open(student_database, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for x in student_fields:
print(x, end='\t |')
print(
"\n-----------------------------------------------------------------"
)

for row in reader:
for item in row:
print(item, end="\t |")
print("\t ")

input("Press any key to continue")


def search_student_ID():
global student_fields
global student_database

print("--- Search Student ---")
ID = input("Enter ID no. to search: ")
with open(student_database, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
if len(row) > 0:
if ID == row[0]:
print("----- Student Found -----")
print("ID: ", row[0])
print("Name: ", row[1])
print("courses: ", row[2])
print("absences: ", row[3])
print("m1: ", row[4])
print("m2: ", row[5])
print("m3: ", row[6])
print("total: ", row[7])
break
else:
print("ID not found in our database")
input("Press any key to continue")


def search_student_courses():
global student_fields
global student_database

print("--- Search Student by courses ---")
courses = input("Enter course to search: ")
with open(student_database, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
if len(row) > 2:
if courses == row[2]:
print("----- Student Found -----")
print("ID: ", row[0])
print("Name: ", row[1])
print("courses: ", row[2])
print("absences: ", row[3])
print("m1: ", row[4])
print("m2: ", row[5])
print("m3: ", row[6])
print("total: ", row[7])
break
else:
print("courses not found in our database")
input("Press any key to continue")


def delete_student():
global student_fields
global student_database

print("--- Delete Student ---")
ID = input("Enter ID. to delete: ")
student_found = False
updated_data = []
with open(student_database, "r", encoding="utf-8") as f:
reader = csv.reader(f)
counter = 0
for row in reader:
if len(row) > 0:
if ID != row[0]:
updated_data.append(row)
counter += 1
else:
student_found = True

if student_found is True:
with open(student_database, "w", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(updated_data)
print("ID ", ID, "deleted successfully")
else:
print("ID not found in our database")

input("Press any key to continue")


while True:
display_menu()

choice = input("Enter your choice: ")
if choice == '1':
add_student()
elif choice == '2':
view_students()
elif choice == '3':
search_student_ID()
elif choice == '4':
search_student_courses()
elif choice == '5':
delete_student()
else:
break

print("-------------------------------")
print(" Thank you for using our system")
print("-------------------------------")

Ireateek (nost acant cal last)
Valaairror
Cipython-inpat-s-erT2est in nodule
ads_atude
lir sheiee
--> 1s3
vie_atud
154
ue choie -
2a_stdant_0
Cspython-inpat-s-ieTazads in vie_atadanta ()
Eor sov in raader
for stan in ov:
print (stan, and-\t 1)
Valoairror: 1/0 spaation en slesed cla.
Transcribed Image Text:Ireateek (nost acant cal last) Valaairror Cipython-inpat-s-erT2est in nodule ads_atude lir sheiee --> 1s3 vie_atud 154 ue choie - 2a_stdant_0 Cspython-inpat-s-ieTazads in vie_atadanta () Eor sov in raader for stan in ov: print (stan, and-\t 1) Valoairror: 1/0 spaation en slesed cla.
1. Add an Stadant
2. Tia Stadanti
3. Saareh Student ay 1D
4. Saareh Student ay sur
. Dalete Student
6. Qust
Inter year shaise: 1
Aas Studant 1Infemation
Inter 1D: 2o000001
Inter nana: h
Intar coan1:
Inta: abane:
Intar ml:
Intar ml:
Inter m3:
Inter sesal: a
Data aved ueatully
Transcribed Image Text:1. Add an Stadant 2. Tia Stadanti 3. Saareh Student ay 1D 4. Saareh Student ay sur . Dalete Student 6. Qust Inter year shaise: 1 Aas Studant 1Infemation Inter 1D: 2o000001 Inter nana: h Intar coan1: Inta: abane: Intar ml: Intar ml: Inter m3: Inter sesal: a Data aved ueatully
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY