Pedro Filipe Pedro Filipe - 5 months ago 8
Python Question

Python 2.7: Error for no reason - 'Invalid Syntax' on for loops

I'm trying to do a chess board, but when it comes to the black sqares, im gettnig the following error:

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 . . .


This is the code:

#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


Can you please explain me what's the problem?

Answer

In the line xi = margem+(a*(comprimento/8) you are missing a closing bracket.

try

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