条件、循环、函数定义练习

本文通过Python的Turtle模块展示了如何绘制五角星、同心圆和太阳花等图案,提供了详细的代码实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.画五角星

import turtle
for i in range(5):
    turtle.forward(100)
    turtle.right(144)

2.画同心圆

import turtle

for i in range(5):

    turtle.circle((i+1)*10)

    turtle.up()

    turtle.goto(0,-(i+1)*10)

    turtle.down()

3.画个太阳花

from turtle import*

color('red')

fillcolor('blue')

begin_fill()

while True:

    forward(200)

    left(170)

    if(abs(pos()))<1:

        break

end_fill()

done()

4.画五个角星

import turtle
turtle.color('yellow')
turtle.bgcolor('red')
turtle.fillcolor('yellow')

def mygoto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()

def ye(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()

mygoto(-320,250)
ye(100)
mygoto(-160,300)
ye(25)
mygoto(-110,250)
ye(25)
mygoto(-110,190)
ye(25)
mygoto(-160,140)
ye(25)

转载于:https://www.cnblogs.com/951111ldj/p/7512216.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值