Python 语法错误
当我在 python 中运行这段代码时,它给了我一个语法错误,并突出显示了我指出的行中的“l”。它为什么要这样做?
from Euler import primeSieve,sumDig
def powerSieve(n):
powers = []
primes = primeSieve(100)
for i in primes:
j = 2
while i ** j <= n:
for k in primes:
if i == k and i ** j >= 10: powers.append(i ** j)
else:
l = 1
while l * (i ** j) <= n:
if l * (i ** j) >= 10: powers.append(l * (i ** j)
##THIS LINE l *= k
j += 1
return sorted(set(powers))
from time import clock
start = clock()
print "Answer to PE119 = ",powerSieve(100)
elapsed = clock() - start
print elapsed * 1000,"ms"
When I run this code in python, it is giving me a syntax error and highlighting the "l" in the line that I have pointed out. Why is it doing this?
from Euler import primeSieve,sumDig
def powerSieve(n):
powers = []
primes = primeSieve(100)
for i in primes:
j = 2
while i ** j <= n:
for k in primes:
if i == k and i ** j >= 10: powers.append(i ** j)
else:
l = 1
while l * (i ** j) <= n:
if l * (i ** j) >= 10: powers.append(l * (i ** j)
##THIS LINE l *= k
j += 1
return sorted(set(powers))
from time import clock
start = clock()
print "Answer to PE119 = ",powerSieve(100)
elapsed = clock() - start
print elapsed * 1000,"ms"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您之前的行中缺少一个右括号。改变这个:
到这个:
You're missing a close bracket on the line before. Change this:
To this:
您忘记关闭前一行的括号。应该是:
You forgot to close the brackets on the preceding line. It should be:
该行上方有一个 if 语句,因此上面的行应以冒号结尾,并且突出显示的行应缩进。
You have an if statement above that line, so the above line should end in a colon and the highlighted line should be indented.