Python includes exercises 31
Title: Please enter the first letter of the week to determine what day of the week, if the first letter of the same, then continue to determine the second letter.
Program Analysis: The case statement is better, if the first letter, as it is determined by the case statement or if statement to determine the second letter. .
Source Code:
#!/usr/bin/python # -*- coding: UTF-8 -*- letter = raw_input("please input:") #while letter != 'Y': if letter == 'S': print ('please input second letter:') letter = raw_input("please input:") if letter == 'a': print ('Saturday') elif letter == 'u': print ('Sunday') else: print ('data error') elif letter == 'F': print ('Friday') elif letter == 'M': print ('Monday') elif letter == 'T': print ('please input second letter') letter = raw_input("please input:") if letter == 'u': print ('Tuesday') elif letter == 'h': print ('Thursday') else: print ('data error') elif letter == 'W': print ('Wednesday') else: print ('data error')
The above example output is:
please input:S please input second letter: please input:a Saturday