I wan to print Student data and Class data. So, I wrote a code to fetch Student_id and Class_id.
Firstly the Input Student_id must match with the Stud_id in Student_data.csv file and print the data according.[I found the answer for this]
Samely, the input class_id must match with the Class_id in Class_data.csv file and print the data according.
I need the Final output as below[marked in **]:
Option 8: Enrol a student to a class Enter student id: S001 Enter class id: C001
- Student S001, Kitty Tan enrolled into class C001, CCW101, Computer and Information Processing *
Code:
if option == 8:
Stud_id = str(input("Enter Student Id : ")).lower()
Clas_id = str(input("Enter Class ID : ")).lower()
Stud_File=open('Student_Data.csv', "r") ## Reading CSV file.
Stud_Reader=list(csv.reader(Stud_File, delimiter=',')) ## Converting the csv file into List.
Class_File=open('Class_Data.csv', "r") ## Reading CSV file.
Class_Reader=list(csv.reader(Stud_File, delimiter=',')) ## Converting the csv file into List.
for row in Stud_Reader: ## Creating a for loop to search sub-string in a string in a CSV file data.
for field in row:
if Stud_id in field:
print("Student " +Stud_id), row[1],(" Enrolled into Class " +Clas_id)
for row in Class_Reader:
for field in row:
if Clas_id in field:
print(row[1], row[2])
Student S001, Kitty Tan enrolled into class C001, CCW101, Computer and Information Processing *
Class_Reader=list(csv.reader(Stud_File, delimiter=','))should probably be reading from theClass_File.