首页 > 解决方案 > 在 python if 语句中使用列表

问题描述

我正在尝试编写一个根据输入为用户提供结果的函数。所以基本上我的功能应该做的是让用户输入一天的值,并在此基础上继续询问用户他们的名字。如果其中一个答案与所需值不匹配,我希望我的代码显示无效条目。我的代码是:

days=[monday, tuesday, wednesday, thursday, friday, saturday, sunday]
def my_function():
    for items in days:
        day=input('what is the day')
        if input==items:
            print('okay')
            for stuff in names:
            name= input("what is your name?")
            if input==stuff:
                print('great')
            else:
                print('invalid entry')  
        else:
            print('invalid entry')

请温柔一点,因为我是 python 新手。提前致谢

标签: pythonfunctionloops

解决方案


if input==items:

这应该是:

if day==items:

input作为函数的 与字符串进行比较没有什么意义。

Smae 问题与您的下一个if.


推荐阅读