Advertisement
Guest User

Course Enrolment

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. catalogueFile = ["CS1P,20,Monday,14,Monday,15,Wednesday,12,Friday,12",
  2. "CS1Q,20,Tuesday,12,Wednesday,15,Wednesday,16,Thursday,12",
  3. "Maths,40,Monday,11,Tuesday,11,Wednesday,11,Thursday,11,Friday,11"]
  4.  
  5. def loadCourseCatalogue(file):
  6. dictionary = {}
  7. for line in file:
  8. line = line.split(",")
  9. dictionary[line[0]] = (int(line[1]), list((line[x],int(line[x+1])) for x in range(2,len(line),2)))
  10. return dictionary
  11. catalogue = loadCourseCatalogue(catalogueFile)
  12. # print(catalogue)
  13.  
  14. def clash(a,b):
  15. result = False
  16. for timeA in catalogue[a][1]:
  17. for timeB in catalogue[b][1]:
  18. if timeA == timeB:
  19. result = True
  20. return result
  21. # print(clash("CS1Q","Maths"))
  22.  
  23. def chooseCourses():
  24.  
  25. userInput = None
  26. credits = 0
  27. enrolledList = []
  28.  
  29. while userInput == None:
  30. while credits < 80:
  31. userInput = input("Please enter course name: ")
  32.  
  33. if userInput not in catalogue.keys():
  34. print("The course name does not exist in the course catalogue.")
  35. userInput = None
  36. else:
  37.  
  38. if userInput in enrolledList:
  39. print("You have already enrolled for this course.")
  40. userInput = None
  41. else:
  42.  
  43. for enrolledCourse in enrolledList:
  44. if clash(userInput,enrolledCourse) == True:
  45. print("You cannot enrol for this course because of a timetable clash with one of your other courses.")
  46. userInput = None
  47.  
  48. enrolledList.append(userInput)
  49. credits += catalogue[userInput][0]
  50. print("You have successfully enrolled for this course.")
  51. print("Current credits: " + str(credits))
  52. userInput = None
  53.  
  54. else:
  55. userInput = True
  56.  
  57. timetable = {"Monday":[], "Tuesday":[], "Wednesday":[], "Thursday":[], "Friday":[]}
  58. for enrolledCourse in enrolledList:
  59. for time in catalogue[enrolledCourse][1]:
  60. timetable[time[0]].append((time[1], enrolledCourse))
  61. for day, times in timetable.items():
  62. print(day)
  63. for time in sorted(times):
  64. print(str(time[0])+": "+time[1])
  65.  
  66.  
  67.  
  68. chooseCourses()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement