首页 > 分享 > Python练习

Python练习

1.绘制天安门效果

在这里插入图片描述
代码实现:

import turtle as t t.hideturtle() t.setup(width=0.9,height=0.9,startx=None,starty=None) t.speed(5) t.pensize(1) t.setx(0) t.sety(0) ###base### t.begin_fill() t.fillcolor(0.8705,0.0784,0.0784) t.goto(-250,0) t.goto(-223.55,150) t.goto(223.55,150) t.goto(250,0) t.goto(0,0) t.end_fill() ##door1# t.begin_fill() t.fillcolor("black") t.goto(20,0) t.goto(20,40) t.right(270) t.circle(20,180) t.goto(-20,0) t.goto(0,0) t.end_fill() ##door2## t.begin_fill() t.fillcolor("black") t.right(90) t.goto(-50,0) t.goto(-50,30) t.right(90) t.circle(15,180) t.goto(-80,0) t.goto(0,0) t.end_fill() ##door3## t.begin_fill() t.fillcolor("black") t.right(90) t.goto(-105,0) t.goto(-105,30) t.right(90) t.circle(15,180) t.goto(-135,0) t.goto(0,0) t.end_fill() ##door4## t.begin_fill() t.fillcolor("black") t.right(90) t.goto(80,0) t.goto(80,30) t.right(90) t.circle(15,180) t.goto(50,0) t.goto(0,0) t.end_fill() ##door5## t.begin_fill() t.fillcolor("black") t.right(90) t.goto(135,0) t.goto(135,30) t.right(90) t.circle(15,180) t.goto(105,0) t.goto(0,0) t.end_fill() ##under## t.penup() t.goto(-249.12,5) t.pendown() t.begin_fill() t.fillcolor("yellow") t.goto(-249.12,5) t.goto(249.12,5) t.goto(250,0) t.goto(-250,0) t.goto(-249.12,5) t.end_fill() ##up## t.penup() t.goto(-224.43,145) t.pendown() t.begin_fill() t.fillcolor("yellow") t.goto(224.43,145) t.goto(223.55,150) t.goto(-223.55,150) t.end_fill() ##leftword## t.penup() t.fillcolor(0.9372,0.9294,0.9294) t.goto(-180,140) t.pendown() t.begin_fill() t.goto(-60,140) t.goto(-60,120) t.goto(-180,120) t.goto(-180,140) t.goto(-180,120) t.end_fill() t.penup() t.fillcolor(0.929,0.180,0.180) t.goto(-177,137) t.pendown() t.begin_fill() t.goto(-63,137) t.goto(-63,123) t.goto(-177,123) t.goto(-177,137) t.end_fill() t.penup() t.goto(-177,123) t.pendown() t.color("white") t.write("中华人民共和国万岁",align="left",font=("华文中宋","10","normal")) t.color("black") ##rightword## t.penup() t.fillcolor(0.9372,0.9294,0.9294) t.goto(180,140) t.pendown() t.begin_fill() t.goto(60,140) t.goto(60,120) t.goto(180,120) t.goto(180,140) t.goto(180,120) t.end_fill() t.penup() t.fillcolor(0.929,0.180,0.180) t.goto(177,137) t.pendown() t.begin_fill() t.goto(63,137) t.goto(63,123) t.goto(177,123) t.goto(177,137) t.end_fill() t.penup() t.goto(63,123) t.pendown() t.color("white") t.write("世界人民大团结万岁",align="left",font=("华文中宋","10","normal")) t.color("black") ##face## t.penup() t.goto(-25,140) t.pendown() t.begin_fill() t.fillcolor(0.9647,0.71764,0.04313) t.goto(25,140) t.goto(25,80) t.goto(-25,80) t.goto(-25,140) t.end_fill() t.penup() t.goto(-23,138) t.pendown() t.begin_fill() t.fillcolor(0.9686,0.8078,0.36862) t.goto(23,138) t.goto(23,83) t.goto(-23,83) t.goto(-23,137) t.end_fill() ###floor## t.penup() t.fillcolor(0.8705,0.0784,0.0784) t.goto(0,151) t.pendown() t.begin_fill() t.goto(160,151) t.goto(160,185.63) t.goto(-160,185.63) t.goto(-160,151) t.goto(0,151) t.end_fill() ##on door1## t.penup() t.goto(-155,150) t.fillcolor(0.6705,0.0588,0.0588) t.pendown() t.left(90) t.begin_fill() t.left(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(15) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() t.penup() t.fillcolor("yellow") t.begin_fill() t.goto(-147,180) t.pendown() t.left(180) for i in range(2): t.fd(9) t.right(90) t.fd(2) t.right(90) t.end_fill() ###lantern## t.penup() t.goto(-135,172) t.pendown() t.fillcolor(0.8705,0.0784,0.0784) t.begin_fill() t.setheading(90) for k in range(2): len=0.2 for i in range(60): if i < 30: len +=0.01 if i >30: len -=0.01 t.fd(len) t.left(3) t.end_fill() t.penup() t.goto(-147,165) t.fillcolor("yellow") t.pendown() t.begin_fill() t.right(90) for i in range(2): t.fd(8) t.right(90) t.fd(10) t.right(90) t.end_fill() ##on door2## t.penup() t.fillcolor(0.6705,0.0588,0.0588) t.begin_fill() t.goto(-110,150) t.pendown() t.left(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(15) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() t.penup() t.fillcolor("yellow") t.begin_fill() t.goto(-102,180) t.pendown() t.left(180) for i in range(2): t.fd(9) t.right(90) t.fd(2) t.right(90) t.end_fill() ###lantern## t.penup() t.goto(-90,172) t.pendown() t.fillcolor(0.8705,0.0784,0.0784) t.begin_fill() t.setheading(90) for k in range(2): len=0.2 for i in range(60): if i < 30: len +=0.01 if i >30: len -=0.01 t.fd(len) t.left(3) t.end_fill() t.penup() t.goto(-102,165) t.fillcolor("yellow") t.pendown() t.begin_fill() t.right(90) for i in range(2): t.fd(8) t.right(90) t.fd(10) t.right(90) t.end_fill() ##on door3## t.penup() t.fillcolor(0.6705,0.0588,0.0588) t.goto(-65,150) t.pendown() t.begin_fill() t.left(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(15) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() t.penup() t.fillcolor("yellow") t.begin_fill() t.goto(-56.5,180) t.pendown() t.left(180) for i in range(2): t.fd(9) t.right(90) t.fd(2) t.right(90) t.end_fill() ###lantern## t.penup() t.goto(-45,172) t.pendown() t.fillcolor(0.8705,0.0784,0.0784) t.begin_fill() t.setheading(90) for k in range(2): len=0.2 for i in range(60): if i < 30: len +=0.01 if i >30: len -=0.01 t.fd(len) t.left(3) t.end_fill() t.penup() t.goto(-56.5,165) t.fillcolor("yellow") t.pendown() t.begin_fill() t.right(90) for i in range(2): t.fd(8) t.right(90) t.fd(10) t.right(90) t.end_fill() ###door 4## t.penup() t.fillcolor(0.6705,0.0588,0.0588) t.goto(-20,150) t.pendown() t.begin_fill() t.left(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(30) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() ##on door5## t.penup() t.fillcolor(0.6705,0.0588,0.0588) t.pendown() t.begin_fill() t.goto(130,150) t.right(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(15) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() t.penup() t.fillcolor("yellow") t.begin_fill() t.goto(138.5,180) t.pendown() t.left(180) for i in range(2): t.fd(9) t.right(90) t.fd(2) t.right(90) t.end_fill() ###lantern## t.penup() t.goto(150,172) t.pendown() t.fillcolor(0.8705,0.0784,0.0784) t.begin_fill() t.setheading(90) for k in range(2): len=0.2 for i in range(60): if i < 30: len +=0.01 if i >30: len -=0.01 t.fd(len) t.left(3) t.end_fill() t.penup() t.goto(138.5,165) t.fillcolor("yellow") t.pendown() t.begin_fill() t.right(90) for i in range(2): t.fd(8) t.right(90) t.fd(10) t.right(90) t.end_fill() ##on door4## t.penup() t.fillcolor(0.6705,0.0588,0.0588) t.begin_fill() t.goto(85,150) t.pendown() t.left(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(15) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() t.penup() t.fillcolor("yellow") t.begin_fill() t.goto(93.5,180) t.pendown() t.left(180) for i in range(2): t.fd(9) t.right(90) t.fd(2) t.right(90) t.end_fill() ###lantern## t.penup() t.goto(105,172) t.pendown() t.fillcolor(0.8705,0.0784,0.0784) t.begin_fill() t.setheading(90) for k in range(2): len=0.2 for i in range(60): if i < 30: len +=0.01 if i >30: len -=0.01 t.fd(len) t.left(3) t.end_fill() t.penup() t.goto(93.5,165) t.fillcolor("yellow") t.pendown() t.begin_fill() t.right(90) for i in range(2): t.fd(8) t.right(90) t.fd(10) t.right(90) t.end_fill() ##on door6## t.penup() t.fillcolor(0.6705,0.0588,0.0588) t.goto(40,150) t.pendown() t.begin_fill() t.left(90) t.fd(25) t.right(90) t.circle(5,90) t.right(90) t.fd(15) t.right(90) t.circle(5,90) t.right(90) t.fd(25) t.right(90) t.fd(25) t.end_fill() t.penup() t.fillcolor("yellow") t.begin_fill() t.goto(48.5,180) t.pendown() t.left(180) for i in range(2): t.fd(9) t.right(90) t.fd(2) t.right(90) t.end_fill() ###lantern## t.penup() t.goto(60,172) t.pendown() t.fillcolor(0.8705,0.0784,0.0784) t.begin_fill() t.setheading(90) for k in range(2): len=0.2 for i in range(60): if i < 30: len +=0.01 if i >30: len -=0.01 t.fd(len) t.left(3) t.end_fill() t.penup() t.goto(48.5,165) t.fillcolor("yellow") t.pendown() t.begin_fill() t.right(90) for i in range(2): t.fd(8) t.right(90) t.fd(10) t.right(90) t.end_fill() ###floor up## t.penup() t.goto(0,185) t.pendown() t.fillcolor(0.6705,0.0588,0.0588) t.begin_fill() t.goto(180,185) t.goto(190,195) t.goto(-190,195) t.goto(-180,185) t.goto(0,185) t.end_fill() ##floor upup## t.penup() t.goto(0,195) t.begin_fill() t.fillcolor(0.9568,0.53333,0.2470) t.pendown() t.goto(190,195) t.goto(190,195+14.7) t.goto(187.73,195+11.94) t.goto(147.88,195+15.42) t.goto(-147.88,195+15.42) t.goto(-187.73,195+11.94) t.goto(-190,195+14.7) t.goto(-190,195) t.goto(0,195) t.end_fill() ##floor2 under### t.penup() t.goto(0,211) t.pendown() t.fillcolor(0.4705,0.8431,0.4117) t.begin_fill() t.goto(130,211) t.goto(130,220) t.goto(-130,220) t.goto(-130,211) t.goto(0,211) t.end_fill() ##floor2## t.penup() t.goto(0,221) t.pendown() t.fillcolor(0.6705,0.0588,0.0588) t.begin_fill() t.goto(140,221) t.goto(150,230) t.goto(-150,230) t.goto(-140,221) t.goto(0,221) t.end_fill() ##country## t.penup() t.goto(0,206.5) t.fillcolor(0.9803,0.9490,0.03137) t.pendown() t.begin_fill() t.circle(8,360) t.end_fill() t.penup() t.goto(0,208) t.fillcolor(0.6705,0.0588,0.0588) t.pendown() t.begin_fill() t.circle(6,360) t.end_fill() ##floor2 up## t.penup() t.goto(0,230) t.begin_fill() t.fillcolor(0.9568,0.53333,0.2470) t.pendown() t.goto(150,230) t.goto(150,240) t.goto(130.08,242.37) t.goto(130.08,277.37) t.goto(127.28,273.77) t.goto(124.23,150+125.51) t.goto(121.5,265.23) t.goto(-121.5,265.23) t.goto(-124.23,150+125.51) t.goto(-127.28,273.77) t.goto(-130.08,277.37) t.goto(-130.08,242.37) t.goto(-150,240) t.goto(-150,230) t.goto(0,230) t.end_fill() t.exitonclick()

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674

相关知识

python基础一
python 绘制一个四瓣花图
Python 水仙花数练习
python玫瑰花代码简单
python玫瑰花代码讲解
S=”Python”,能够显示输出Python的选项是:
《Think Python》练习 4
【Python】(二)数据类型与转换
如何用简单的Python绘制一朵花
如何用python画一朵花

网址: Python练习 https://m.huajiangbk.com/newsview858968.html

所属分类:花卉
上一篇: 大班美术教案及教学反思《天安门》
下一篇: 大班上学期美术教案《天安门》含反