python123第三周答案_Python123第二周自由练习

一、画五角星

描述

画一个五角星,画笔用黄色,用红色填充,效果如下所示。 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

aa495d6482c2cd59c86ae899b81e.png

代码如下:

#画五角星

import turtle

turtle.pensize(5)

turtle.pencolor("yellow")

turtle.fillcolor("red")

turtle.begin_fill()

for i in range(5):

turtle.forward(120)

turtle.right(144)

turtle.forward(120)

turtle.left(72)

turtle.end_fill()

turtle.hideturtle() #隐藏画笔

turtle.done() #结束绘制

效果图如下:

1966853-20200314162203861-124996685.png

二、画一组同心圆

描述

利用turtle库画一组同心圆。用户输入最小圆的半径、圆的个数和画笔颜色,每个相邻圆半径相差20。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输入格式

第一行输入一个正整数,作为最小圆的半径‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

第二行输入一个正整数,作为圆的个数‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

第三行输入画笔颜色的英文名,如red, blue, green等‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输出格式

aed6dc8949927bb90287ef55304a.png

代码如下:

#画一组同心圆

rmin=eval(input())

number=eval(input())

color=input()

import turtle as t

t.pencolor(color)

t.pensize(4)

for i in range (number):

t.circle(rmin)

rmin=rmin+20

t.penup()

t.seth(-90)

t.fd(20)

t.seth(0)

t.pendown()

t.hideturtle()

t.done()

输入:

50

5pink

效果图如下:

1966853-20200314163850403-956259096.png

三、渐变的圆

描述

利用turtle库的circle(50)函数可以画半径为50的圆,circle(50,steps=n)可以画半径为50的圆的内接正n边形,利用这个方法绘制示例中的图形,设置画笔为蓝色并用黄色填充图形。n由用户输入,要求n>=3且小于10。(注意:最后一个必须是圆,不能是正多边形)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输入格式

一个大于等于3且小于10的正整数‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输出格式

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

d2c2e5eec4a14a78d09179494543.png

代码如下:

#渐变的圆

import turtle

number = int(input()) #把用户输入转成整数

turtle.screensize(600,500,'white')

turtle.pensize(3) #设置画笔宽度为3

turtle.pencolor('blue') #设置画笔颜色为黑色

turtle.fillcolor('yellow') #设置填充颜色为黄色

turtle.begin_fill() #开始填充

turtle.forward(-50)

for i in range(3,number):

turtle.circle(50, steps=i)

turtle.forward(100)

turtle.circle(50, steps=number)

if number == 1:

turtle.circle(50)

else:

turtle.forward(100)

turtle.circle(50)

turtle.end_fill()

turtle.hideturtle() #隐藏海龟

turtle.done()

输入:

9

效果图如下:

1966853-20200314165409676-10932705.png

五、画奥运五环

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

描述

参考以下代码,利用turtle库画奥运五环,圆半径为45.

代码如下:

#画奥运五环

import turtle

coordA=(-100,0,100,-50,70)

coordB=(-20,-20,-20,-70,-70)

turtle.width(5)

turtle.color("red")

turtle.penup()

turtle.goto(coordA[0],coordB[0])

turtle.pendown()

turtle.circle(45)

turtle.color("blue")

turtle.penup()

turtle.goto(coordA[1],coordB[1])

turtle.pendown()

turtle.circle(45)

turtle.color("green")

turtle.penup()

turtle.goto(coordA[2],coordB[2])

turtle.pendown()

turtle.circle(45)

turtle.color("yellow")

turtle.penup()

turtle.goto(coordA[3],coordB[3])

turtle.pendown()

turtle.circle(45)

turtle.color("black")

turtle.penup()

turtle.goto(coordA[4],coordB[4])

turtle.pendown()

turtle.circle(45)

turtle.hideturtle()

turtle.done()

效果图如下:

1966853-20200324103535403-1338689371.png

六、画太极图

描述

利用turtle库画以下太极图形状.

f30494833a61790d8306be0e4f7a.png

代码如下:

#绘制太极图

from turtle import *

setup(800,800,100,100)

#绘制左半部分

fillcolor('#FFFFFF')

begin_fill()

circle(100,180)

circle(200,180)

seth(180)

circle(-100,180)

end_fill()

seth(90)

penup()

fd(85)

pendown()

seth(0)

fillcolor('#000000')

begin_fill()

circle(25)

end_fill()

seth(-90)

penup()

fd(85)

pendown()

seth(180)

#绘制右半部分

fillcolor('#000000')

begin_fill()

circle(100,180)

circle(200,180)

seth(0)

circle(-100,180)

end_fill()

seth(-90)

penup()

fd(85)

pendown()

seth(-180)

fillcolor('#FFFFFF')

begin_fill()

circle(25)

end_fill()

hideturtle()

done()

效果图如下:

1966853-20200314160220621-489936214.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值