0
我想寫一個代碼,但有什麼問題。 我無法打印功能的結果。 這裏是什麼錯在我的代碼迷你例如:功能Python錯誤
import math
def area(r):
"It will display the area of a circle with radius r"
A = math.pi*r**2
print("The answer is:", str(A))
return A
area(3)
print(str(A)) # This line is not working
# NameError: name 'A' is not defined
解決您的壓痕請。 –
另外,你沒有在任何地方分配'area(3)'的返回值。當函數被調用時,'return A'語句不會自動創建一個'A'變量。 –
[如何從函數返回值?](https://stackoverflow.com/questions/19080943/how-to-return-a-value-from-a-function)可能的重複 –