球体的体积和表面积可用下列公式计算。将其创建为终端应用程序。写一个体积函数和另一个表面积函数。结果应显示体积和表面积,精确到小数点后2位。使用Python数学模块中的pi。包括以下博士。你必须拿到通行证 所有的测试都要获得满分。请密切注意如何命名函数。他们必须 匹配
卷示例/博士:
表面积示例/博士:
MY CODE:
''' Python3 program to calculate Volume and
Surface area of Sphere'''
# Importing Math library for value Of PI
import math
pi = math.pi
# Function to calculate Volume of Sphere
def volume(r):
vol = (4 / 3) * pi * r * r * r
return vol
# Function To Calculate Surface Area of Sphere
def surfacearea(s):
sur_ar = 4 * pi * r * r
return sur_ar
# Driver Code
radius = round(volume(1), 2)
area = round(area(0), 2)
print( "Volume Of Sphere : ", volume(radius) )
print( "Surface Area Of Sphere : ", surfacearea(area) )
因为这里没有明显的问题,我假设目标是完成数学函数并通过博士测试。话虽如此,要做到这一点就不可能不犯数学错误,因为表面积函数的最后两个doctest是错误的,
round(surface_area(18.9), 2)
应该是4488.83而不是13959.84,round(surface_area(33.33), 2)
应该是13934.72而不是155093.84。你知道吗下面的两个程序将求出半径为的球体的表面积和体积。这只是一个简单的方法。第一个程序更精确,但两者都能完成任务。你知道吗
或者
相关问题 更多 >
编程相关推荐