Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- catalogueFile = ["CS1P,20,Monday,14,Monday,15,Wednesday,12,Friday,12",
- "CS1Q,20,Tuesday,12,Wednesday,15,Wednesday,16,Thursday,12",
- "Maths,40,Monday,11,Tuesday,11,Wednesday,11,Thursday,11,Friday,11"]
- def loadCourseCatalogue(file):
- dictionary = {}
- for line in file:
- line = line.split(",")
- dictionary[line[0]] = (int(line[1]), list((line[x],int(line[x+1])) for x in range(2,len(line),2)))
- return dictionary
- catalogue = loadCourseCatalogue(catalogueFile)
- # print(catalogue)
- def clash(a,b):
- result = False
- for timeA in catalogue[a][1]:
- for timeB in catalogue[b][1]:
- if timeA == timeB:
- result = True
- return result
- # print(clash("CS1Q","Maths"))
- def chooseCourses():
- userInput = None
- credits = 0
- enrolledList = []
- while userInput == None:
- while credits < 80:
- userInput = input("Please enter course name: ")
- if userInput not in catalogue.keys():
- print("The course name does not exist in the course catalogue.")
- userInput = None
- else:
- if userInput in enrolledList:
- print("You have already enrolled for this course.")
- userInput = None
- else:
- for enrolledCourse in enrolledList:
- if clash(userInput,enrolledCourse) == True:
- print("You cannot enrol for this course because of a timetable clash with one of your other courses.")
- userInput = None
- enrolledList.append(userInput)
- credits += catalogue[userInput][0]
- print("You have successfully enrolled for this course.")
- print("Current credits: " + str(credits))
- userInput = None
- else:
- userInput = True
- timetable = {"Monday":[], "Tuesday":[], "Wednesday":[], "Thursday":[], "Friday":[]}
- for enrolledCourse in enrolledList:
- for time in catalogue[enrolledCourse][1]:
- timetable[time[0]].append((time[1], enrolledCourse))
- for day, times in timetable.items():
- print(day)
- for time in sorted(times):
- print(str(time[0])+": "+time[1])
- chooseCourses()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement