#cube
lengthC= input('Give me the side length of your cube')
areaC=6*(int(lengthC)**2)
volumeC =(int(lengthC)**3)
print('The volume of your cube is',volumeC,'and your area is',areaC)
程序通过输入获取半径来查找表面积和体积
•
问答
wosongxiangyi 回答:程序通过输入获取半径来查找表面积和体积
一个球的表面积是4 pi x半径** 2,体积是4/3 x pi x半径** 3等等
import math
radius= int(input('Give me the radius of your sphere'))
areaS=4 * math.pi * (radius**2)
volumeS = (4/3) * math.pi * (radius ** 3)
print('The volume of your sphere is',volumeS,'and your area is',areaS)
,
与其他公式完全相同:
import math
lengthC= input("Give me the side length of your cube: ")
areaC=6*(int(lengthC)**2)
volumeC =(int(lengthC)**3)
print('The volume of your cube is',volumeC,areaC)
lengthR = input("Give me the radius of the sphere: ")
volumE = (4/3) * math.pi * (float(lengthR)**3)
areaE = 4 * math.pi * (float(lengthR)**2)
print('The volume of your sphere is',volumE,areaE)
输出:
Give me the side length of your cube: 3
The volume of your cube is 27 and your area is 54
Give me the radius of the sphere: 9
The volume of your sphere is 3053.6280592892786 and your area is 1017.8760197630929