Closed. This question is not reproducible or was caused by typos。它当前不接受答案。












想改善这个问题吗?更新问题,以便将其作为on-topic用于堆栈溢出。

4年前关闭。



Improve this question




我正在尝试制作棋盘,但是当涉及到黑色广场时,我会收到以下错误:
      File "C:\Users\Pedro\Dropbox\Aplicativos\NONIOInforestudante\Licenciatura em BioquÝmica\2015 2016\2.║ Semestre\Computadores e ProgramaþÒo\graph\f10-p1.py", line 17
    yi = margem+((a-1)*(largura/8))
     ^
SyntaxError: invalid syntax
Press any key to continue . . .

这是代码:
#from graphics import *
import graphics

largura = 500
comprimento = 500
margem = 20

janela = graphics.GraphWin('Janela', comprimento+2*margem, largura+2*margem)
janela.setBackground('grey')
c = graphics.Rectangle(graphics.Point(margem, margem), graphics.Point(comprimento+margem,largura+margem))
c.setFill('white')
c.setOutline('black')
c.setWidth(1)
c.draw(janela)
for a in range(1,8,2):
    xi = margem+(a*(comprimento/8)
    yi = margem+((a-1)*(largura/8))
    xf = margem+(a*((comprimento/8)*2)
    yf = margem+(a*largura/8)
    c = graphics.Rectangle(graphics.Point(xi, yi),graphics.Point(xf, yf)
    c.setFill('black')
    c.draw(janela)
janela.getMouse()
janela.close

你能告诉我什么问题吗?

最佳答案

在xi = margem+(a*(comprimento/8)行中,您缺少右括号。

尝试

xi = margem+(a*(comprimento/8))

关于python - Python 2.7 : Error for no reason - 'Invalid Syntax' on for loops [closed],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37957198/

10-10 22:29