|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def fun1(x):
if x==1|x==2 :
return 1
elif x>2:
return fun1(x-1) + fun1(x-2)
month=int(input("请输入月份:"))
result=fun1(month)
print("第%d月总共有%s只兔子!" % (month, result))
Traceback (most recent call last):
File "D:\新建文件夹\test1.py", line 7, in <module>
result=fun1(month)
File "D:\新建文件夹\test1.py", line 5, in fun1
return fun1(x-1) + fun1(x-2)
File "D:\新建文件夹\test1.py", line 5, in fun1
return fun1(x-1) + fun1(x-2)
File "D:\新建文件夹\test1.py", line 5, in fun1
return fun1(x-1) + fun1(x-2)
[Previous line repeated 7 more times]
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
是因为方法返回值没有类型吗?
if x==1|x==2 :
改为
if x==1 or x==2 :
|
|