编程中list1的大小问题
编了个小程序,两重循环,求list1,当n = 3,4,……,10时,均能算出,当n = 11时,算不出结果了,是数字大了?还是数字多了列表装不下?或者出现死循环?请帮忙看看!多谢!程序如下:
n = int(input('n>=3?'));
kn = 0 ;
while 2**(n+kn) < 3**n :
kn = kn + 1 ;
kn = kn - 1 ;
m = n + kn + 1 ;
mlist = [];
for i in range(0,n) :
mlist.append(1);
list1 = [];
while mlist[0] < 1 + kn + 1 :
mlist[n-1] = mlist[n-1] + 1 ;
for i in range(1 , n ) :
if mlist[n - i ] == 1 + kn + 1 :
mlist[n - i ] = 1 ;
mlist[n - i - 1] = mlist[n - i - 1] + 1 ;
sumlist = 0;
for j in range(0,n):
sumlist = sumlist + mlist[j] ;
if sumlist == m :
list1 = list1 + mlist ;
print(list1);