Surely you want to see the courses in order. dict
values are inherently without order. So using a list
might be more appropriate than using a dict
here.
monday = ["1 - English",
"2 - Maths",
"3 - PE",
"4 - Computing",
"5 - Computing"]
if choice_day == "monday" and choice_period == "NO":
for course in monday:
print(course)
By not using a dict you avoid having to sort, or use a list declaring that period 1 comes before period 2, etc. (e.g. order = ['P1', 'P2', ...]
). The list makes the order built-in.
If for some reason you needed to access, say, the 3rd course on Monday, since Python uses 0-based indexing, you'd write monday[2]
.
You may, however, want to use a dict to represent the entire schedule:
schedule = {'monday': ["1 - English",
"2 - Maths",
"3 - PE",
"4 - Computing",
"5 - Computing"]
'tuesday': [...]}
You would use a dict
here since the user may enter any day of the week.
If you were always accessing the schedule in order, then you'd want to use an ordered data structure like a list or tuple.
Now you could handle any value for choice_day
like this:
if choice_period == "NO":
for course in schedule[choice_day]:
print(course)
(Be sure to think about how you want to handle the case when the user enters a choice_day
that does not exist... One possibility is to vet the choice when it is entered. Another alternative is to use a try..except
here. A third -- my preference -- is to use argparse.)
Anyway, using a dict for schedule
allows you to avoid mind-numbing code like:
if choice_day == 'monday':
...
elif choice_day == 'tuesday':
...