2.1

-- coding: utf-8 --

"""
Created on Sat Mar 15 09:54:37 2025

@author: xijie
"""

TempConvert.py

TempStr = eval(input("请输入温度值:"))
Fuhao = input("请输入对应温度的符号:")
if Fuhao in ['F','f']:
C = (TempStr-32)/1.8
print("转换后的温度是{:.0f}C".format(int(round(C))))
elif Fuhao in ['C','c']:
F = 1.8*TempStr+ 32
print("转换后的温度是{:.0f}F".format(int(round(F))))
else:
print("输入格式错误")
2.2列品源:

-- coding: utf-8 --

"""
Created on Sat Mar 15 10:34:18 2025

@author: xijie
"""

Zhongliang = input("请输入带有符号的重量:")
if Zhongliang[-1] in ['g','G']:
Bang = eval(Zhongliang[0:-2])*2.2046
print("转换后的重量是{:.4f}LB".format(Bang))
elif Zhongliang[-1] in ['b','B']:
Gongjin = eval(Zhongliang[0:-2])/2.2046
print("转换后的金额是{:.4f}KG".format(Gongjin))
else:
print("输入格式错误")

列品源:
2.3

列品源:

DrawColorfulPython.py

import turtle

定义颜色列表(可根据需要调整颜色顺序)

colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple']

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.pencolor(colors[i % len(colors)])
turtle.circle(40, 80)
turtle.circle(-40, 80)

绘制蟒蛇头部

turtle.pencolor(colors[4 % len(colors)])
turtle.circle(40, 80/2)
turtle.pencolor(colors[5 % len(colors)])
turtle.fd(40)
turtle.pencolor(colors[6 % len(colors)])
turtle.circle(16, 180)
turtle.pencolor(colors[0 % len(colors)])
turtle.fd(40 * 2/3)

turtle.done()

列品源:
2.4

列品源:

DrawPython.py

import turtle
turtle.setup(500.500)
turtle.fd(100)
turtle.left(120)
turtle.fd(100)
turtle.left(120)
turtle.fd(100)

列品源:
2.5

列品源:

DrawPython.py

import turtle
turtle.setup(500.500)
turtle.fd(100)
turtle.left(120)
turtle.fd(100)
turtle.left(120)
turtle.fd(100)
turtle.left(120)
turtle.fd(50)
turtle.left(60)
turtle.fd(50)
turtle.left(120)
turtle.fd(50)
turtle.left(120)
turtle.fd(50)

列品源:
2.6

列品源:

DrawPython.py

import turtle
turtle.setup(500.500)
turtle.left(30)
turtle.fd(180)
turtle.right(120)
turtle.fd(270)
turtle.right(120)
turtle.fd(270)
turtle.right(120)
turtle.fd(90)
turtle.left(60)
turtle.fd(90)
turtle.right(120)
turtle.fd(270)
turtle.right(120)
turtle.fd(270)
turtle.right(120)
turtle.fd(180)
turtle.done()

列品源:
2.7

列品源:
import turtle
pen = turtle.Turtle()
pen.speed(0)

step = 10

for _ in range(50):
pen.forward(step)
pen.right(90)
pen.forward(step)
pen.right(90)
step += 10

turtle.done()

posted on 2025-03-16 20:12  986614  阅读(11)  评论(0)    收藏  举报