输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。
def day_of_week():
s1 = input("please input the first letter:")
week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
lst = [x for x in week if x.lower().startswith(s1.lower())]
while len(lst) > 1:
s = input("please input the next letter:")
s1 += s
lst = [x for x in week if x.lower().startswith(s1.lower())]
if not lst:
print('please input the right letter!')
dow = day_of_week()
lst = [dow]
return lst[0]
if __name__ == '__main__':
print(day_of_week())
#!/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')
以上实例输出结果为:
please input:S
please input second letter:
please input:a
Saturday
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。