1
我试图获得所有可能的骰子组合排列。以下是我的代码。AttributeError:'NoneType'对象没有属性'append'(递归函数)
def PrintAllPerms(n, arr, str_):
if (n == 0):
print str_
arr.append(str_)
return arr
else:
for i in ["1","2","3","4","5","6"]:
str_ = str_ + i
arr = PrintAllPerms(n-1,arr,str_)
str_ = str_[:-1]
PrintAllPerms(2,[],"")
但是打印后只有这么多,我得到以下错误。
PrintAllPerms(2,[],"")
11
12
13
14
15
16
21
<ipython-input-7-d03e70079ce2> in PrintAllPerms(n, arr, str_)
2 if (n == 0):
3 print str_
----> 4 arr.append(str_)
5 return arr
6 else:
AttributeError: 'NoneType' object has no attribute 'append'
为什么直到2,1打印呢?
什么是正确的方式来解决这个问题?