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

本程序接受用户输入的半径和高,并计算并输出以下值:

  • 圆周长
  • 圆面积
  • 球面积
  • 球体积
  • 圆柱体积

输入格式:

输入为两个 double 型数字,分别代表半径和高,以空格隔开。

输出格式:

分行输出五个结果,每个结果保留两位小数。

示例:

输入:

1.5 3

输出:

9.42
7.07
28.27
14.14
21.21

代码示例:

import math

radius, height = map(float, input().split())

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}')
Python 计算圆周长、圆面积、球面积、球体积和圆柱体积

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

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