''' Purpose: gain experience with if-elif-else ''' # report message based on day of week # Sunday: weekend day # Monday: start of school week # Tuesday: school day # Wednesday: school day # Thursday: school day # Friday: end of school week # Saturday: weekend day # get day of interest reply = input( 'Enter day of week: ' ) # put day in standard format - first letter capitalized, others lower case day = reply.strip() day = day.capitalize() # capitalize makes every letter lowercase except # the first letter # day = reply.strip().capitalize() # alternatively could also be written as print( ) # analyze and report on day # How can I use if, elif, and else statements to get the right thing to print? # if ( test expression ): # if this test expression is true then we do # do this # what's indented ''' if ( day == 'Sunday' ): print( 'weekend day' ) # response = 'weekend day' / # just print response at end elif ( day == 'Monday' ): print('start of school week') elif( day == 'Tuesday' ): print( 'school day' ) elif( day == 'Wednesday' ): print( 'school day' ) elif( day == 'Thursday' ): print( 'school day' ) elif( day == 'Friday' ): print( 'end of school week' ) elif (day == 'Saturday' ): print( 'weekend day' ) else: # Any other input jumps into this else statement print( 'Did not supply name of day of week' ) ''' ''' if ( (day == 'Saturday') or (day == 'Sunday') ): # day == 'Saturday' or 'Sunday' # won't work because 'Sunday' # is always True response = 'weekend day' elif ( day == 'Tuesday' or day == 'Wednesday' or day == 'Thursday' ): response = 'school day' elif ( day == 'Monday' ): response = 'start of school week' elif( day == 'Friday' ): response = 'end of school week' else: response ='Not a day' print( response ) ''' if ( day in ['Saturday','Sunday'] ): # if day is an element of the list print( 'weekend day' ) elif ( day in ['Tuesday','Wednesday','Thursday'] ): print( 'school day' ) elif ( day == 'Monday' ): # if the day string is equivalent to the string 'Monday' print('start of school week' ) elif( day == 'Friday' ): print( 'end of school week' ) else: pass # do nothing # Having an else statement is not mandatory. # Having an else is useful if you just want to test for like any other # possibility like if (possibility), elif (possibility), else: do this if # it didn't meet the other possibilities (otherwise do this)\