Python 2.7:无缘无故的错误 - 'Invalid Syntax' for 循环



我正在尝试制作国际象棋板,但是当涉及黑色sqares时,im gettnig以下错误:

      File "C:UsersPedroDropboxAplicativosNONIOInforestudanteLicenciatura em BioquÝmica2015 20162.║ SemestreComputadores e ProgramaþÒographf10-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))

相关内容

  • 没有找到相关文章

最新更新