Jul-09-2020, 04:01 PM
(This post was last modified: Jul-09-2020, 04:01 PM by deanhystad.)
I think your problem stated out by incorrectly interpreting the assignment. From the assignment:
By the way, the exasperated "There has got to be a better way!" test is what I use to let me know when the approach I am using is most likely wrong and that it is time to close the editor and do some research.
Quote:First title case the passed in day argumentYou are asked, as the first thing in your program, to title case the passed in day assignment. I do not see where you are doing that. If the day is title cased it will match the case of the keys in the dictionary. If you get an invalid key error, you know the day is invalid, and not just a case error. So start by doing what is asked in the assignment.
(so monday or MONDAY both result in Monday).
day = day.capitalize()As for a key error, that is common. Anybody who writes a program that uses a dictionary lookup and allows free-form user input will have a way to handle invalid keys. Your solution could be made to work, but it is a terrible solution. Recreating the dictionary keys in sets is brittle and error prone and lengthy. Do you think anyone would program in Python if they had to do things like this to use a dictionary? Of course not. There must be a better way. I wonder how many pages show up if you google "handle Python KeyError".
By the way, the exasperated "There has got to be a better way!" test is what I use to let me know when the approach I am using is most likely wrong and that it is time to close the editor and do some research.