Python练习6( 二 )


6. 输出如下图所示的字符、 数字金字塔
s = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']for i in range(len(s)):for j in range(8 - i):print(' ', end='')print((s[len(s) - i - 1]) * 2 * (i + 1))print()for i in range(9):for j in range(8 - i):print(' ', end='')print(str(9 - i) * 2 * (i + 1))
7. 绘制随机大小、随机位置、随机颜色的爱心 。
colors = ['purple', 'red', 'pink', 'blue', 'green', 'pink', 'white', 'orange', 'yellow']import turtle as timport randomfor i in range(20):t.seth(45)color = colors[random.randint(0, len(colors) - 1)]t.fillcolor(color)t.penup()x = random.randint(-500, 500)y = random.randint(-300, 300)t.goto(x, y)r = random.randint(1, 360)t.right(r)t.pendown()t.begin_fill()a = random.randint(30, 150)t.circle(0 - a, 180)t.fd(2 * a)t.right(90)t.fd(2 * a)t.circle(0 - a, 180)t.end_fill()t.penup()t.done()