1
這是我的Python代碼:Python函數返回None,而不是價值
def pyramid_volume(base_length, base_width, pyramid_height):
base_area = base_length * base_width
pyramid_volume = base_area * pyramid_height * 1/3
return
print('Volume for 4.5, 2.1, 3.0 is:', pyramid_volume(4.5, 2.1, 3.0))
它打印Volume for 4.5, 2.1, 3.0 is: None
有人能幫助我嗎?
通過@DavisThuy代碼看起來像帕斯卡爾來練習(被指定這樣的返回值)。在Python中,我會避免創建一個與函數同名的局部變量(看起來不必要地混淆了我)。只要寫'return base_area * pyramid_height * 1/3'即可 – kratenko