#Office Hours in Python
day_in_question = input("Please enter a specific day abbreviation " + \
"(M,T,W,Th,F) to see my office hours: ").capitalize()
day_hour = {
'M':'8:30am-9:30am',
'T':'8:30am-10:30am',
'W':'8:30am-9:30am',
'Th':'8:30am-10:30am'
}
your_visit = day_hour.get(day_in_question[0],"by appointment")
print("For your requested day, my office hours are {0}.".format(your_visit))
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.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.