Created
November 2, 2017 17:26
-
-
Save gitdagray/ded4ca34321000581397bd92043162ee to your computer and use it in GitHub Desktop.
Python Office Hours: A simple example with my office hours... that compares user input to dictionary keys and returns the corresponding value. By making the comparison with get(value_to_compare, default_value), the default value of "by appointment" is returned if the user input does not match one of the dictionary keys.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
day_in_question = input("\nIn order to see my office hours for a given day, " + \ | |
"\n...please enter the specific day or day abbreviation: ").capitalize() | |
print("\nThank you for entering: {0}.".format(day_in_question)) | |
if (day_in_question[0] == "M" or | |
day_in_question[0] == "T" or | |
day_in_question[0] == "W" or | |
day_in_question[0] == "F"): | |
if day_in_question[:2] == "Th": | |
my_day = "Th" | |
else: | |
my_day = day_in_question[0] | |
day_hour = { | |
'M':'8:30am-9:30am', | |
'T':'8:30am-10:30am', | |
'W':'8:30am-9:30am', | |
'Th':'9:30am-10:30am' | |
} | |
your_visit = day_hour.get(my_day,"by appointment") | |
print("\nOn {1}, my office hours are {0}.".format(your_visit,day_in_question)) | |
else: | |
print("\nSorry, I do not have office hours on {0}.".format(day_in_question)) | |
again = input("\nWould you like to enter another day? (y/n): ").lower() | |
if again[0] == "y": | |
continue | |
else: | |
print("\nGoodbye!") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment