我是初学python程序员,试图执行这段代码,但我还不太了解def功能......有人能指出代码中的错误以及如何修复它们吗?
import math
def main():
radius = get_radius()
calculate = cal_volume()
dis = display()
def get_radius():
rad = float(input("Enter the radius :"))
return rad
def cal_volume(radius):
return 4/3*math.pi*radius**3
def display(cal_volume):
print("The volume is :",cal_volume)
main()
答案 0 :(得分:1)
您没有在cal_volume()
中为display()
和def main()
提供参数。
应该是:
import math
def main():
radius = get_radius()
calculate = cal_volume(radius)
dis = display(calculate)
# print out the result?
def get_radius():
rad = float(input("Enter the radius :"))
return rad
def cal_volume(radius):
return 4/3*math.pi*radius**3
def display(cal_volume):
print("The volume is :",cal_volume)
main()
答案 1 :(得分:0)
试试这个:
import math
def main():
radius = get_radius()
calculate = cal_volume(radius)
dis = display(calculate)
def get_radius():
rad = float(input("Enter the radius :"))
return rad
def cal_volume(radius):
return 4/3*math.pi*radius**3
def display(cal_volume):
print("The volume is :",cal_volume)
main()