python - 在 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 新手。提前致谢
解决方案
if input==items:
这应该是:
if day==items:
将input
作为函数的 与字符串进行比较没有什么意义。
Smae 问题与您的下一个if
.
推荐阅读
- azure - 将文件保存到子目录中的 Azure 文件共享
- permissions - 将正确的用户/组设置为 Apache 服务器/项目
- python - 在包含数字的指定嵌套列表中查找最大数字
- c# - SkiaSharp SKMatrix.PostConcat 过时了吗?
- c# - Asp.net MVC DropDownListFor 来自模型的列表列表
- android - 如何编写 Room Dao 查询以在 Android 中基于单表中的可选多列搜索唯一数据?
- flutter - 在 Flutter 中使用 awesome_notifications 显示通知的问题
- angular - 从角度模板多次调用方法
- java - Java:将 HEX 字节数组转换为 16 个固定长度的二进制字符串
- python - confluent-kafka python客户端版本适用于confluent-kafka 5.5.1版本