Python 计算圆周长、面积、球体积和圆柱体积

本程序使用 Python 代码计算圆周长、圆面积、球表面积、球体积和圆柱体积。

输入格式: 输入为 double 型,分别代表圆的半径和圆柱的高度。

输出格式: 分行输出,保留 2 位小数。

代码示例:

import math

radius = float(input())
height = float(input())

circumference = 2 * math.pi * radius
area_circle = math.pi * radius ** 2
area_sphere = 4 * math.pi * radius ** 2
volume_sphere = 4/3 * math.pi * radius ** 3
volume_cylinder = math.pi * radius ** 2 * height

print(f'{circumference:.2f}')
print(f'{area_circle:.2f}')
print(f'{area_sphere:.2f}')
print(f'{volume_sphere:.2f}')
print(f'{volume_cylinder:.2f}')

输出结果示例:

6.28
12.57
50.27
33.51
9.42
Python 计算圆周长、面积、球体积和圆柱体积

原文地址: https://www.cveoy.top/t/topic/R0j 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录