1醋虏,for循環(huán)嵌套寻咒; (x,y從坐標(biāo)中心不斷變大)
import pgzrun
n = 50
def draw():
for y in range(n,600,2*n):50 150 250 350
for x in range(n,600,2*n):50 150 250 350
screen.draw.filled_circle((x,y),n,'blue')
pgzrun.go()
2颈嚼,用for循環(huán)嵌套產(chǎn)生很多矩陣排列隨機(jī)顏色同心圓:
import pgzrun
import random
n = 100
def draw():
screen.fill('white')
for y in range(n,600,2*n):
for x in range(n,600,2*n):
for r in range (n,0,-10):
screen.draw.filled_circle((x,y),r,\
(random.randint(0,255),random.randint(0,255),\
random.randint(0,255)))
pgzrun.go()
3毛秘,列表【】基本用法
列表內(nèi)容和序號(hào)的區(qū)別:
color = ['red','white','blue']
col = color[0]
print(col)
col = color[2]
print(col)
以上關(guān)于顏色的列表用于隨機(jī)顏色就是:
import pgzrun
WIDTH = 800
HEIGHT = 400
colors = ['red','orange','yellow','green','blue','purple','white','cyan'] #有8個(gè)隨機(jī)顏色
def draw():
screen.fill('white')
for r in range (8):
screen.draw.filled_circle((400,400),400-r*30,colors[r]) #r是隨機(jī)8個(gè)顏色之一,r的數(shù)值只能取‘0-7’
pgzrun.go()
xlist = [] #空列表 范圍在從0開始 0阻课,1叫挟,2,3限煞,4抹恳,5----中取
for i in range (1,6): # 1 2 3 4 5
xlist.append(i) # 給列表增加內(nèi)容 1,2署驻,3奋献,4,5
print(xlist)
xlist = [1,2,3,4,5]
for i in range(1,5): #i = 1,2,3,4
xlist[i] = 2*xlist[i] #1屬于序號(hào)0旺上,所以1不動(dòng)瓶蚂,其他數(shù)值內(nèi)容變化
print(xlist)
x數(shù)值的單列寫法:
xlist = [1,2,3,4,5]
for x in xlist:
print(x)
關(guān)于len(長度)的用法:(結(jié)果為:5)
xlist = [2,6,3,4,8]
print(len(xlist))