程序员的浪漫,教你用Python代码画圣诞树

这篇博客介绍了如何使用Python的Turtle库创作出不同效果的圣诞树,通过两种方法展示了编程的趣味性和创造性。鼓励读者尝试动手,并祝大家学习进步。
摘要由CSDN通过智能技术生成

如何用Python画一个圣诞树呢?

最简单:

1height = 5
2
3stars = 1
4for i in range(height):
5    print((' ' * (height - i)) + ('*' * stars))
6    stars += 2
7print((' ' * height) + '|')

效果:

640?wx_fmt=png

哈哈哈哈,总有一种骗了大家的感觉。

其实本文是想介绍Turtle库来画圣诞树。

方法一:

1import turtle
 2screen = turtle.Screen()
 3screen.setup(800,600)
 4circle = turtle.Turtle()
 5circle.shape('circle')
 6circle.color('red')
 7circle.speed('fastest')
 8circle.up()
 9square = turtle.Turtle()
10square.shape('square')
11square.color('green')
12square.speed('fastest')
13square.up()
14circle.goto(0,280)
15circle.stamp()
16k = 0
17for i in range(1, 17):
18    y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值