1.第一个题目 画五环
import turtle as t
t.setup(700,400)
t.penup()
t.goto(-80,0)
t.pendown()
t.pencolor("blue")
t.pensize(3)
t.circle(50
)t.penup()
t.goto(0,0)
t.pendown()
t.pencolor("black")
t.pensize(3)
t.circle(50)
t.penup()
t.goto(80,0)
t.pendown()
t.pencolor("red")
t.pensize(3)
t.circle(50)
t.penup()
t.goto(-40,-80)
t.pendown()
t.pencolor("yellow")
t.pensize(3)
t.circle(50)
t.penup()
t.goto(40,-80)
t.pendown()
t.pencolor("green")
t.pensize(3)
t.circle(50)
t.done()
2.第二题demo2
r = float(input("Enter the radius of a cylinder= "))
l = float(input("Enter the length of a cylinder= "))
import math
Π = math.pi
area = r * r * Π
volume = area * l
print(f"The area is {area} ")
print(f"The volume is {volume}")
3.第三题demo5
M = float(input("Enter the amount of water in kilograms :"))
I = float(input("Enter the initial temperature :"))
F = float(input("Enter the final temperature :"))
Q = M * (F - I) * 4184
print(f"The energe needed is:{Q}")
4.第四题demo25
T = int(input("Enter today's day :"))
E = int(input("Enter the number of days elapsed since today :"))
F = (T + E % 7)
print(f"Today is {T} and the future day is {F}")
Python编程:图形绘制与数学计算示例
这篇文章包含四个Python代码片段。第一个使用turtle模块绘制奥运五环;第二个计算圆柱体的面积和体积;第三个求解水加热所需的能量;第四个则涉及日期的加法运算。这些示例展示了Python在基础图形绘制、数学运算和输入输出处理方面的应用。
2303

被折叠的 条评论
为什么被折叠?



