`题目:请用英文输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。
运用函数的方式来实现
data=[‘Monday’,‘Tuesday’,‘Wednesday’,‘Thursday’,‘Friday’,‘Saturday’,‘Sunday’]
data_seoncd=[‘Tuesday’,‘Thursday’,‘Saturday’,‘Sunday’]
def first(word):
first=False
for i in data:
if word==i[0]:
first=True
return first
def second(word):
second=False
for i in data_seoncd:
if word==i[1]:
second=True
return second
def check_first(word):
check=False
for i in data:
if word in ['M','W','F'] and word==i[0]:
print ('今天星期{}'.format(i))
def check_second(first,second):
check=False
for i in data_seoncd:
if second==i[1] and first==i[0] :
if first+second in ['Tu','Th','Sa','Su']:
print ("今天星期{}".format(i))
check=True
else:
check=False
return check
while True:
word=input('请输入第一个单词')
big_word=word.upper()
if first(big_word)==False:
print ('第一个单词不是星期开头')
elif first(big_word)==True and big_word in ['M','W','F']:
check_first(big_word)
break
else:
second_word=input('请输入第二个字母')
if second(second_word)==False:
print ("第二个字母不符合规则")
elif second(second_word)==True:
if check_second(big_word,second_word)==True:
break
elif check_second(big_word,second_word)==False:
print ('不存在')
break