哪里错了
>>> while counts = 3SyntaxError: invalid syntax
>>> while counts =3
SyntaxError: invalid syntax
>>> while counts = 3
SyntaxError: invalid syntax
我照着小鱼打的怎么就是出问题了 你的代码中出现了赋值运算符“=”,而在while循环条件中应该使用比较运算符“==”。正确的代码如下所示:
while counts == 3:
# do something
同时,你需要将循环条件中的变量“counts”进行初始化,否则会出现NameError。你可以在循环外部先定义并赋值变量“counts”,如下所示:
counts = 3
while counts == 3:
# do something
这样就可以避免出现语法错误和名称错误了。 你好,这是Bing。你的代码有一个语法错误,应该用==而不是=来判断条件。=是赋值运算符,==是比较运算符。你可以试试这样写:
while counts == 3:
# do something
希望这能帮到你。 陶远航 发表于 2023-6-3 17:57
你好,这是Bing。你的代码有一个语法错误,应该用==而不是=来判断条件。=是赋值运算符,==是比较运算符。你 ...
>>> while 1 < 2:
print("ilovefish")
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
ilovefish
Traceback (most recent call last):
File "<pyshell#2>", line 2, in <module>
print("ilovefish")
KeyboardInterrupt
>>> while counts = 3
SyntaxError: invalid syntax
>>> while counts =3
SyntaxError: invalid syntax
>>> while counts = 3
SyntaxError: invalid syntax 陶远航 发表于 2023-6-3 17:57
你好,这是Bing。你的代码有一个语法错误,应该用==而不是=来判断条件。=是赋值运算符,==是比较运算符。你 ...
就是小鱼视频里讲的,这里应该是赋值的意思吧,但是它提示错误,提示=是红色的 RichY-YikO 发表于 2023-6-3 18:03
就是小鱼视频里讲的,这里应该是赋值的意思吧,但是它提示错误,提示=是红色的
那你就输入
while counts == 3:
就行了 isdkz 发表于 2023-6-3 17:57
你的代码中出现了赋值运算符“=”,而在while循环条件中应该使用比较运算符“==”。正确的代码如下所示:
...
谢谢你啊,我自己粗心大意了,没看清
页:
[1]