python的几个小程序
是作业,比较简单,所以不怎么走心(笑)
python版本:3.8.5 64-bit
IDE:VScode(别和我说vscode不算IDE)
汇率转换
money=input("请输入带有“¥”或者“$”符号的数值:")
if money[-1]in['¥']:
m=(eval(money[0:-1])/6)
print("转换后的金额为{:.2f}$".format(m))
elif money[-1]in['$']:
m=(eval(money[0:-1])*6)
print("转换后的金额为{:.2f}¥".format(m))
else:
print("输入错误")
彩色蟒蛇
import turtle as t
t.setup(650,350,200,200)
t.penup()
t.fd(-250)
t.pendown()
t.pensize(25)
t.pencolor("purple")
color=['green','red','blue','gold']
t.seth(-40)
for i in range(4):
t.pencolor(color[i])
t.circle(40,80)
t.circle(-40,80)
t.circle(40,40)
t.fd(40)
t.circle(16,180)
t.fd(40*2/3)
t.done()
正方形螺旋线
import turtle as t
t.pen(speed=0)
t.penup()
t.goto(-200, -200)
t.pendown()
t.seth(0)
length = 400
while (length !=0):
t.fd(length)
t.left(90)
length -= 2.5
t.done()
等边三角形
import turtle as t
for i in range(3):
t.forward(300)
t.left(120)
t.done()
叠三角形
import turtle as t
t.fd(200)
t.right(120)
t.fd(200)
t.right(120)
t.fd(200)
t.right(60)
t.fd(200)
t.right(120)
t.fd(400)
t.right(120)
t.fd(400)
t.right(120)
t.fd(200)
无角四边形
import turtle as t
t.fd(200)
t.penup()
t.fd(50)
t.left(90)
t.fd(50)
t.pendown()
t.fd(200)
t.penup()
t.fd(50)
t.left(90)
t.fd(50)
t.pendown()
t.fd(200)
t.penup()
t.fd(50)
t.left(90)
t.fd(50)
t.pendown()
t.fd(200)
六芒星
import turtle as t
for i in range(3):
t.fd(40)
t.right(120)
t.fd(40)
for i in range(3):
t.fd(40)
t.left(120)
t.fd(40)
for i in range(3):
t.fd(40)
t.right(120)
t.right(60)
t.fd(40)
for i in range(3):
t.fd(40)
t.right(120)
t.right(60)
t.fd(40)
for i in range(3):
t.fd(40)
t.right(120)
t.right(60)
t.fd(40)
for i in range(3):
t.fd(40)
t.right(120)
小熊(贼丑)
import turtle as t
t.setup(500,1000)
t.pen(speed=0)
t.penup()
t.left(90)
t.fd(200)
t.right(90)
t.pendown()
t.colormode(255)
t.fillcolor((128,64,0))
t.begin_fill()
t.circle(75)
t.end_fill()
t.penup()
t.pencolor((128,64,0))
t.goto(-55,295)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()
t.pencolor((128,64,0))
t.goto(55,295)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
t.pencolor((0,0,0,))
t.fillcolor((0,0,0))
t.penup()
t.goto(25,275)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(-25,275)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.pensize(5)
t.goto(0,225)
t.pendown()
t.circle(20)
t.pensize(3)
t.penup()
t.goto(0,245)
t.pendown()
t.goto(0,265)
t.penup()
t.goto(0,245)
t.pendown()
t.goto(-10,230)
t.penup()
t.goto(0,245)
t.pendown()
t.goto(10,230)
t.penup()
t.goto(0,205)
t.pencolor((128,64,0))
t.fillcolor((128,64,0))
t.pendown()
t.begin_fill()
t.circle(-100)
t.end_fill()
t.penup()
t.goto(-90,150)
t.pendown()
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(90,150)
t.pendown()
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(-70,-5)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()
t.goto(70,-5)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
t.done()
小熊(download来的方案)
from turtle import*
tracer(10)
ht()
fillcolor('#B8860B')
pensize(10)
pencolor('#5E2612')
penup()
goto(-70, -85)
seth(135)
pendown()
begin_fill()
circle(18, 180)
circle(200, 17)
seth(-90)
circle(400, 13)
circle(18, 180)
seth(-104)
circle(18, 180)
circle(400, 13)
seth(28)
circle(200, 17)
circle(18, 180)
end_fill()
#body white
penup()
goto(0, -185)
fillcolor("white")
pencolor("white")
seth(0)
pendown()
begin_fill()
circle(20, 22.5)
circle(30, 135)
circle(20, 45)
circle(30, 135)
circle(20, 22.5)
end_fill()
fillcolor('#B8860B')
pencolor('#5E2612')
seth(-22.5)
penup()
goto(0, 0)
fd(120)
pendown()
seth(60)
begin_fill()
circle(75, 45)
circle(125, 135)
circle(75, 45)
circle(125, 135)
end_fill()
pensize(17)
penup()
goto(45, 0)
pendown()
circle(5, 360)
penup()
goto(-45, 0)
pendown()
circle(5, 360)
#face white
penup()
seth(-22.5)
fd(75)
seth(60)
pendown()
fillcolor("white")
begin_fill()
pencolor("white")
circle(15, 45)
circle(30, 135)
circle(15, 45)
circle(30, 135)
end_fill()
fillcolor('#B8860B')
pencolor('#5E2612')
penup()
goto(0, -15)
pendown()
pensize(10)
seth(0)
circle(5, 360)
seth(-45)
fd(20)
penup()
goto(0, -15)
seth(-135)
pendown()
fd(20)
penup()
goto(65, 100)
circle(35, 170)
pendown()
begin_fill()
circle(35, 205)
end_fill()
penup()
goto(-65, 100)
seth(-45)
circle(-35, 175)
pendown()
begin_fill()
circle(-35, 195)
end_fill()
#heart
penup()
goto(150, 150)
seth(45)
pencolor("red")
fillcolor("red")
pendown()
begin_fill()
fd(19)
circle(25, 45)
circle(11.25, 180)
seth(90)
circle(11.25, 180)
circle(25, 45)
fd(19)
end_fill()
done()