欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。

程序员文章站 2022-04-15 11:06:02
``` def juge(num,week_list): w = input('请输入第%s个字母:'%num) w = w.lower() res = [] state = 0 for week in week_list: if w == week[0 + num - 1: 1 + num - 1... ......
def juge(num,week_list):

    w = input('请输入第%s个字母:'%num)
    w = w.lower()
    res = []
    state = 0
    for week in week_list:
        if w == week[0 + num - 1: 1 + num - 1]:
            state += 1
            res.append(week)

    if state == 1:
        print('是%s'% res[0])
    elif state > 1:
        print('还要输入一次')
        num += 1
        week_list = res
        juge(num, week_list)
    else:
        print('非法输入')


if __name__ == '__main__':
    #  初始条件
    num = 1
    week_list = ['mon', 'tues', 'wed', 'thur', 'fri', 'sat', 'sun']
    juge(num, week_list)