python实现圣诞树

Posted 人生苦短,我用python!!!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python实现圣诞树相关的知识,希望对你有一定的参考价值。

先来个迷你的 *_*

height = 5
stars = 1
for i in range(height):
    print((\' \' * (height - i)) + (\'*\' * stars))
    stars += 2
print((\' \' * height) + \'|\')


再整个花里胡哨的

import turtle
screen = turtle.Screen()
screen.setup(800,600)
circle = turtle.Turtle()
circle.shape(\'circle\')
circle.color(\'red\')
circle.speed(\'fastest\')
circle.up()
square = turtle.Turtle()
square.shape(\'square\')
square.color(\'green\')
square.speed(\'fastest\')
square.up()
circle.goto(0,280)
circle.stamp()
k = 0
for i in range(1, 17):
    y = 30*i
    for j in range(i-k):
        x = 30*j
        square.goto(x,-y+280)
        square.stamp()
        square.goto(-x,-y+280)
        square.stamp()
    if i % 4 == 0:
        x = 30*(j+1)
        circle.color(\'red\')
        circle.goto(-x,-y+280)
        circle.stamp()
        circle.goto(x,-y+280)
        circle.stamp()
        k += 2
    if i % 4 == 3:
        x = 30*(j+1)
        circle.color(\'yellow\')
        circle.goto(-x,-y+280)
        circle.stamp()
        circle.goto(x,-y+280)
        circle.stamp()
square.color(\'brown\')
for i in range(17,20):
    y = 30*i
    for j in range(3):
        x = 30*j
        square.goto(x,-y+280)
        square.stamp()
        square.goto(-x,-y+280)
        square.stamp()
turtle.exitonclick()

以上是关于python实现圣诞树的主要内容,如果未能解决你的问题,请参考以下文章

最美圣诞树!用Python画棵雪夜圣诞树送给你

200行Html5+CSS3+JS代码实现动态圣诞树

python实现圣诞树

用Python画出圣诞树,瞧瞧我这简易版的吧

python圣诞树编写实例详解

python圣诞树编写实例详解