python
num = int(input("请输入一个数字:"))
square = num*num;
print(num,"的平方为:",square)
a=int(input("请输入矩形的高:"))
b=int(input("请输入矩形的宽:"))
print("矩形的面积为:",end="")
print(a*b)
for i in range(1,101):
print(i,end=" ")
sum = 0
for i in range(1,101):
sum += i
print('1~100之间所有数字之和是:',sum)
numbers = []
# 循环遍历10以内的自然数
for i in range(1, 11):
# 判断是否不能被3整除
if i % 3 != 0:
numbers.append(i)
# 将列表中的元素从大到小排序并输出
numbers.sort(reverse=True)
for num in numbers:
print(num)
# 使用两层循环来生成九九乘法表
for i in range(1, 10):
for j in range(1, i+1):
# 计算乘积并以格式化的方式输出
product = i * j
print(f"{j} × {i} = {product}", end="\t")
print() # 换行
for x in range(1, 20):
for y in range(1, 33):
z = 100 - x - y
if 5 * x + 3 * y + z / 3 == 100:
print("公鸡数量:{},母鸡数量:{},小鸡数量:{}".format(x, y, z))
import math
# 计算矩形的面积
def rectangle_area(width, height):
return width * height
# 计算圆形的面积
def circle_area(radius):
return math.pi * radius * radius
# 计算梯形的面积
def trapezoid_area(top, bottom, height):
return (top + bottom) * height / 2
# 主程序
if __name__ == "__main__":
# 调用函数计算面积并输出结果
width = float(input("请输入矩形的宽度:"))
height = float(input("请输入矩形的高度:"))
rectangle = rectangle_area(width, height)
print("矩形的面积为:", rectangle)
radius = float(input("请输入圆的半径:"))
circle = circle_area(radius)
print("圆的面积为:", circle)
top = float(input("请输入梯形的上底:"))
bottom = float(input("请输入梯形的下底:"))
height = float(input("请输入梯形的高度:"))
trapezoid = trapezoid_area(top, bottom, height)
print("梯形的面积为:", trapezoid)