【发布时间】:2020-07-02 20:00:18
【问题描述】:
如何使用下面的公式在python中计算金字塔的表面积?
面积 = 底^2 + 底√(底^2 + 4 ∙ 高度^2)
import math
def main():
# Your main code goes here
b = eval(input("Enter the base: "))
h = eval(input("Enter the height: "))
print("The surface area of the pyramid is : ",Area)
# Create a method here to calculate pyramid area
# ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
import math
def calcPyramid(b,h):
Area = math.pow(b * b + b (math.sqrt(b * b + 4 * h * h)))
return Area
##########################################################
# This will run your main method when we load the project.
# Do not change this `if` statement or your program will fail all tests on
Gradescope!
###########################################################
if __name__ == '__main__':
main()
【问题讨论】:
-
在您的计算中,您有:
b * b + b (...)。对于 python,b(...)看起来像一个函数调用,您期望b是函数的名称。您的意思是:b * b + b * ( ... )?
标签: python methods computer-science