2.1:
TemStr=eval('input("请输入带有符号的温度值:")')
if TemStr[-1] in ["F","f"]:C=int((eval(TemStr[0:-1])-32)/1.8)print("转换后的温度是:{}C".format(C))
elif TemStr[-1] in ["C","c"]:F=int(1.8*eval(TemStr[0:-1])+32)print("转换后的温度是:{}F".format(F))
else:print("输入的格式错误")
2.2:
#2.2: 1$=6¥汇率转换
CashStr=input("请输入带有单位的货币:")
if CashStr[-1] in ["$"]:RMB=eval(CashStr[0:-1])*6print(f"转换后的人民币为:{RMB}元")
elif CashStr[-1] in ["¥"]:dollar=eval(CashStr[0:-1])/6print(f"转换后的美元为:{dollar}美刀")
else:print("输入格式错误")
2.3:
#2.3 1千克=2.2046磅 千克与英制磅的转换
WeightStr=input("请输入带有单位的重量数:")
if WeightStr[-2:] in ["kg"]:BangShu=eval(WeightStr[0:-2])*2.2046print(f"转换后的磅数为:{BangShu}Ib")
elif WeightStr[-2:] in ["Ib"]:QianKeShu=eval(WeightStr[0:-2])/2.2046print(f"转换后的千克数为:{QianKeShu}kg")
else:print("您输入的格式有误,斯密马赛")
#2.4 彩色蟒蛇(每绘制蟒蛇的一小段颜色就发生一次变换):
import turtle
import random
turtle.colormode(255)
turtle.setup(650,350,200,200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.seth(-40)
for i in range(4):turtle.circle(40,80)turtle.circle(-40,80)turtle.color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40* 2/3)
2.5:
#2.5 等边三角形绘制:
import turtle
turtle.setup(650,350,200,200)
turtle.speed(2)
turtle.penup()
turtle.goto(0,100)
turtle.pendown()
turtle.pensize(15)
turtle.seth(-120)
turtle.fd(150)
turtle.seth(0)
turtle.fd(150)
turtle.seth(120)
turtle.fd(150)
2.6:
#2.6叠加等边三角形の绘制:
import turtle
import random
turtle.colormode(255)
turtle.setup(650,350,200,200)
turtle.speed(2)
turtle.penup()
turtle.goto(0,100)
turtle.pendown()
turtle.pensize(15)
turtle.seth(-120)
turtle.fd(150)
turtle.seth(0)
turtle.fd(150)
turtle.seth(120)
turtle.fd(150)
turtle.penup()
turtle.seth(-120)
turtle.fd(75)
turtle.pendown()
turtle.color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
turtle.seth(0)
turtle.fd(75)
turtle.seth(-120)
turtle.fd(75)
turtle.seth(120)
turtle.fd(75)
2.7:
#2.7六角形的绘制:
import turtle as t
t.setup(650,350,200,200)
t.speed(2)
t.pensize(10)
t.pendown()
t.goto(0,-120)
t.seth(30)
t.fd(120)
t.left(120)
t.fd(120)t.seth(0)
t.penup()
t.forward(69.28)
t.pendown()
t.seth(-150)
t.fd(120)
t.seth(-30)
t.fd(120)
t.seth(90)
t.fd(120)
2.8:
#2.8正方形螺旋线绘制:
import turtle
turtle.setup(600, 600)
turtle.speed(10)
turtle.pensize(2)
turtle.color("blue") length = 10
for i in range(50): turtle.forward(length)turtle.right(90) length += 5 turtle.done()