1
我是一個開始的python程序員,但已經寫了幾個腳本,其中包括我定義我自己的函數並使用它們的腳本。我似乎無法讓任何用戶定義的函數在IDLE中工作。想知道我是否瘋了/愚蠢。可有人請解釋以下結果感謝:簡單函數不起作用,看不到錯誤
def f(x,y):
solution = x+y
return solution
f(2,2)
SyntaxError: invalid syntax
>>> a = f(2,2)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a = f(2,2)
NameError: name 'f' is not defined
def g(x):
solution = x + 2
return solution
g(2)
SyntaxError: invalid syntax
>>> a = g(2)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
a = g(2)
NameError: name 'g' is not defined
男人,編輯和打我回答 - 如果我可以,我會+1兩次:) – RocketDonkey