我是Python新手(记住这一点),并且正在刺探初学者书中的示例之一。其中有一个程序在屏幕上绘制随机圆圈。但是,尽管将字符复制为字符,但circle.py
的第19行仍存在语法错误。有人可以花时间为我查看代码吗? (顺便说一句,对于一个初学者,我的Python OK理解。我得到函数,变量和面向对象编程,但我不知道以后太多了。)看不到语法错误
1 import pygame, random
2
3 class Circle:
4 _minimum=100;_maximum=255
5 _colour=None
6 _properties=[]
7
8 def __init__(self,screen,width,height):
9 self.random_colour()
10 self.draw_circle(screen,width,height)
11
12 def draw_circle(self, screen, width, height):
13 x=random.randint(1,width)
14 y=random.randint(1,height)
15 size=random.randint(1,5)
16 self.properties=[x,y,size]
17 pygame.draw.circle(screen,self._colour,(x,y),size)
18
19 def random_colour(self)
20 red=random.randint(self._minimum,self._maximum)
21 green=random.randint(self._minimum,self._maximum)
22 blue=random.randint(self._minimum,self._maximum)
23 self._colour=[red,green,blue]
24
25 def clear_circle(self,screen):
26 pygame.draw_circle(screen,(0,0,0),(self._properties[0],self._properties[1],self._properties[2]
感谢您的帮助,在所有。
没有义务在块之间进行一致的缩进。 – njzk2
njzk2是对的,这不是一个错误。当然,每个缩进级别使用一致的空间量是一个好主意,但是Python仅仅相对于前一行和下一行查看缩进级别。 – Onyxite
同意。在每个块内,缩进必须一致,但是两个不同块之间的缩进可能不同。 Python可能不会抱怨,但其他开发人员会。 – SethMMorton