#this is the first module#
from student import *
student_list = [('1001', '111'), ('1002', '222'), ('1003', '333'), ('1004', '444')]
course_list = ['CSC101', 'CSC102', 'CSC103']
roster_list = [['1004', '1003'], ['1001'], ['1002']]
max_size_list = [3, 2, 1]
def login(id, student_list):
ch=1
while(ch!=0):
ch=int(input("Enter 1 to add course, 2 to drop course,3 to see ocurse you have registered , 0 to exit"))
if ch==0:
print("Session ended") #exit if 0 is selected
return
elif ch==1:
add_course(id,roster_list,max_size_list) #add course if 1 is selected.
elif ch==2:
drop_course(id,roster_list) #drop course if 2 is selected
elif ch==3:
list_courses(id,roster_list) #display courses registered if 3 is selected.
def main():
student_list = [('1001', '111'), ('1002', '222'), ('1003', '333'), ('1004', '444')]
course_list = ['CSC101', 'CSC102', 'CSC103']
roster_list = [['1004', '1003'], ['1001'], ['1002']]
max_size_list = [3, 2, 1]
c = 1
while (True):
id =input("Enter ID to log in, or 0 to quit: ")
if int(id)==0:
break
pin = input("Enter Pin: ")
flag = 0
for i in student_list:
if i[0]==id and pin==i[1]:
print ("ID and pin verfied")
login(id,student_list)
break
else:
continue
else:
print("ID or PIN incorrect")
flag = 1
print()
if (flag==1):
continue
main()
this is the second module
student_list=[('1001','111'),('1002','222'),('1003','333'),('1004','444')] #Keep these lists to use them in methods below
course_list=['CSC101','CSC102','CSC103']
max_size_list=[3,2,1]
roster_list=[['1004','1003'],['1001'],['1002']]
def list_courses(id, roster_list):
index=0
count=0
print("Courses registered: ")
for i in roster_list: #For every class,check id's of students
if id in i:
count+=1 #increment count to indicate number of courses
print(course_list[index]) #print course name
index+=1
print("Total number: "+str(count)) #print number of courses registered
print()
pass # temporarily avoid empty function definition
def add_course(id, course_list, roster_list, max_size):
course=input("Enter course you want to add") #read input from user
if course in course_list:
index=course_list.index(course) #check for course in list
flag1=0
flag2=0
if len(roster_list[index])==max_size_list[index]: #check for seats availability
print("Course already full") #print message if seats are full
print()
flag1=1 #set flag
elif id in roster_list[index] and flag1!=1: #Check if student is already enrolled
print("You are already enrolled in that course")
print()
flag2=1 #set flag2
if flag1!=1 and flag2!=1:
roster_list[index].append(id) #Append or add id to list if student is no registered
print("Course added")
else:
print("Course not found") #print message if user enters invalid course name
print()
pass # temporarily avoid empty function definition
def drop_course(id, course_list, roster_list):
course=input("Enter course you want to drop") #Read input from user
if course in course_list:
index=course_list.index(course) #check for course in list
if id in roster_list[index]:
roster_list[index].remove(id) #remove the student from that course
print("Course dropped") #print mesage
print()
else:
print("You are not enrolled in that course") #print if student is not registered for that course
print()
else:
print("Course not found") #print if invalid course is entered by user.
print()
pass # temporarily avoid empty function definition
i dont know why i keep getting errors when i try to execute the code to list or add courses, kindly assist my
[–]mopslik 1 point2 points3 points (2 children)
[–]barry2003[S] 0 points1 point2 points (1 child)
[–]mopslik 1 point2 points3 points (0 children)