gpt4 book ai didi

python - "or"Python 中的条件问题

转载 作者:太空狗 更新时间:2023-10-29 21:13:31 24 4
gpt4 key购买 nike

我正在学习 Python,但遇到了一些小问题。在我正在上的类(class)中看到类似的东西后想出了这个简短的脚本。我在成功之前将“或”与“如果”一起使用(此处显示不多)。出于某种原因,我似乎无法正常工作:

test = raw_input("It's the flying circus! Cool animals but which is the best?")
x = test.lower()

if x == "monkey" or "monkeys":
print "You're right, they are awesome!!"
elif x != "monkey" or "monkeys":
print "I'm sorry, you're incorrect.", x[0].upper() + x[1:], "is not the right animal."

但这很好用:

test = raw_input("It's the flying circus! Cool animals but which is the best?")
x = test.lower()

if x == "monkey":
print "You're right, they are awesome!!"
elif x != "monkey":
print "I'm sorry, you're incorrect.", x[0].upper() + x[1:], "is not the right animal."

可能 or 条件不适合这里。但我已经尝试过,等等。我希望有一种方法可以让它接受一个或多个猴子,而其他一切都会触发 elif。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com