不理解错误消息:for语句中的语法无效
问题描述:
我正在写一个非常简单的程序,使用for循环输出数字0-10。然而,当我点击运行时,会出现语法错误,在第8行中用红色突出显示“=”。我不明白为什么它是错的?我在空闲模式下使用python 3.5.2。不理解错误消息:for语句中的语法无效
def numbers():
print ("This program will count to ten, just you wait...")
import time
time.sleep(1)
print ("\n\nLiterally wait I just need to remember base 10 because I
only work in binary!")
time.sleep(4)
int(counter) = 0
for counter <**=** 9:
print ("\n" + counter)
counter = counter + 1
print ("\n\nAnd there you go. Told you I could do it. Goodbye :) ")
time.sleep(2)
exit()
numbers()
答
试试这样说:
def numbers():
print ("This program will count to ten, just you wait...")
import time
time.sleep(1)
print ("\n\nLiterally wait I just need to remember base 10 because I only work in binary!")
time.sleep(4)
for i in range(1, 10): #11 if you want 10 to be printed
print i
print ("\n\nAnd there you go. Told you I could do it. Goodbye :) ")
time.sleep(2)
答
几个百分点。摘录如下:
int(counter) = 0
for counter <**=** 9:
print ("\n" + counter)
counter = counter + 1
有多个错误。
-
int(counter) = 0
是无效的Python语法。 -
for counter <**=** 9
不是有效的for
声明。 - 行
print ("\n" + counter)
和counter = counter + 1
缺乏正确的缩进。
取代那些4行
for counter in range(10):
print(counter)
你'for'声明是无效的。您正在寻找'while',或[Python文档](http://python.org)。 –
'int(counter)= 0'是什么意思?这是无效的Python语法。它应该读'counter = 0'。 –