风火轮编程的考试题目:红黑点阵

风火轮编程的考试题目:红黑点阵

编写程序画以下图形,包括直角坐标系,点的直径是10,对角线点的颜色红,其它为黑。点与点的距离是25。

python点阵图

python点阵图


以下是参考代码:

import turtle

turtle.speed(0);turtle.delay(0)
turtle.fd(300);turtle.stamp();turtle.bk(600);turtle.fd(300);turtle.left(90)
turtle.fd(300);turtle.stamp();turtle.bk(600);turtle.fd(300);turtle.right(90)
turtle.penup()

d = 25
for i in range(-5,6):
    for j in range(-5,6):
        if i==j or i+j==0:
            turtle.color('red')
        else:
            turtle.color('black')
        x = i*d
        y = j*d
        turtle.goto(x,y)
        turtle.dot(10)
turtle.ht()

李兴球

李兴球的博客是Python创意编程原创博客

You must be logged in to post a comment