Python Don';无法理解错误消息:for语句中的语法无效
我正在编写一个非常简单的程序,使用for循环输出0-10的数字。但是,当我单击run时,它出现了一个语法错误,在第8行以红色突出显示“=”。我不明白为什么错了?我正在空闲模式下使用python 3.5.2Python Don';无法理解错误消息:for语句中的语法无效,python,for-loop,numbers,syntax-error,equals,Python,For Loop,Numbers,Syntax Error,Equals,我正在编写一个非常简单的程序,使用for循环输出0-10的数字。但是,当我单击run时,它出现了一个语法错误,在第8行以红色突出显示“=”。我不明白为什么错了?我正在空闲模式下使用python 3.5.2 def numbers(): print ("This program will count to ten, just you wait...") import time time.sleep(1) print ("\n\nLiterally wait I ju
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():
打印(“此程序将计数为10,请稍候…”)
导入时间
时间。睡眠(1)
打印(“\n\n请稍候,我只需要记住基数10,因为我
只能在二进制文件中工作!)
时间。睡眠(4)
整数(计数器)=0
对于计数器,这是错误的语法。根据:
for语句用于迭代序列(如字符串、元组或列表)或其他iterable对象的元素
这不是您的情况,或者您可以使用range()
创建序列:
for i in range(1, 10):
然而,这是人为的解决办法,虽然它会起作用,但并不是你真正应该做的
您应该使用而不是。说:
只要表达式为true,while语句就用于重复执行
当计数器时,像这样尝试:
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
您的for
语句无效。您正在查找while
,或者。您对int(counter)=0的意图是什么?这不是有效的python语法。它应该是计数器=0
。好的。非常感谢。
int(counter) = 0
for counter <**=** 9:
print ("\n" + counter)
counter = counter + 1
for counter in range(10):
print(counter)