import turtle
t = turtle.Pen()
t.speed(0)
geZi = 11 # 格子数量
kuanDu = 10 # 格子宽度
changDu = geZi*kuanDu # 棋盘总宽度
# 画横线,格子数量+1
for i in range(geZi + 1):
t.penup()
t.goto(-changDu, changDu - i * kuanDu)
t.pendown()
t.goto(0, changDu - i * kuanDu)
# 画竖线,格子数量+1
for i in range(geZi + 1):
t.penup()
t.goto(-changDu + i * kuanDu, changDu)
t.pendown()
t.goto(-changDu + i * kuanDu, 0)
turtle.done()
Python循环画棋盘
扫描二维码,在手机上阅读