myName = input("Hey there, what's your name?")
print("Hello",myName,"!")
print("Here's a game called ''Guess my number'', in this game you will have to guess my number in 5 tips, I will think of a number between 1 and 20.")
ready = input("Are you readyyyy!?")
if ready = "yes" or "yeah" or "totally" or "hell yeah" or "yupp" or "yepp" or "uhumm" or "sure": <-- here's the problem it says, at "sure"'s 1st "-sign
print("Let's go!")
loop = "y"
else:
print("I'm sorry to hear that.")
loop "n"
初学者可以请任何人帮助。我试图删除并添加新词,我重新注视程序和计算机,因为有明显的错误。如果我删除类似“确定”的单词,则指针仍将指向相同的确切位置,但是那里什么也没有。
最佳答案
您在=
语句中使用了一个if
符号。那是不允许的。如果要检查是否相等,则需要使用==
。 =
运算符仅用于赋值语句。
虽然将=
更改为==
将解决语法错误,但您的代码仍无法完全正确地工作。这是因为==
不会分布在您显示的所有or
选项上。表达式a == b or c
被解释为(a == b) or c
,并且如果c
是“truthy”(因为任何非空字符串都将是),则该表达式将被视为true。
相反,您可能想使用类似if ready in {"yes", "yeah", "totally"}
的东西。这将创建一个常量set
对象,并测试ready
变量的值是否在集合中(这是快速检查)。
关于python - 在这个非常基本的代码中,我无法弄清楚第6行的语法错误是(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28889127/