作者coeric (coeric)
看板Python
标题[问题] 问个很蠢的问题,原谅我
时间Fri May 25 16:15:27 2007
我自订了一个函数
------------------
def f(x):
s = sin(2*x)
print s
a=f(1)
b=f(2)
print a+b
------------------
他却无法加总,出现
Traceback (most recent call last):
File "/home/coeric/workspace1/电脑模拟/text.py", line 13, in <module>
print a+b
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
烦请各位大大用力批吧~~我想破头就是不知道哪出问题
因为若我直接使用sin(1)+sin(2) 可以算阿~~
自订函数後就不能算了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.120.109.8
1F:推 Tiberius:print s -> return s 囧 05/25 16:22
2F:推 coeric:非常感恩!!!我算是初学者,范例里面没说要打return... 05/25 17:04
3F:→ coeric:我以为不用,经大大这麽一讲,我想起PHP也要return...=.=" 05/25 17:05