塔利班
发表于 2018-3-28 23:17:41
fan1993423 发表于 2018-3-28 23:11
我当时就在想怎么打印换行,我就一直在想\n用循环加进去,后来我发现做不来,就放弃了
列表都生成的了,肯定可以做打印啊,,
坑得飞起
发表于 2018-3-28 23:34:35
坑得飞起 发表于 2018-3-27 20:42
n=int(input())
i,j,s1,s2=1,1,[],[]
while (i0) :
def newlist(n):
i,j,s1,s2=1,1,[],[]
while (i<=n)and(n>0) :
if i==int(0.5*j*j+0.5*j) :
s2.append(i)
s1.append(s2)
s2,j=[],j+1
else :
s2.append(i)
i+=1
if s2!=[] :
s1.append(s2)
return s1
嘻嘻,没长眼睛
wyf345491656
发表于 2018-3-29 00:02:22
看完大家的答案发现我理解错意思了。。。还以为输出的中间有换行=。=
idol
发表于 2018-3-29 09:19:01
idol 发表于 2018-3-28 10:52
C:\Users\Administrator\Desktop\1.png
colinshi
发表于 2018-3-29 10:57:34
wyf345491656 发表于 2018-3-29 00:02
看完大家的答案发现我理解错意思了。。。还以为输出的中间有换行=。=
我觉得你是没理解二维数组的写法。
776667
发表于 2018-3-29 11:01:49
def fun172(n):
if n == 0:
return [[]]
list_n =
result_list = []
length = 1
while length <= len(list_n):
result_list.append(list_n[:length])
list_n = list_n
length += 1
if list_n:
result_list.append(list_n)
return result_list
if __name__ == '__main__':
n = input('输入数字:')
print(fun172(n))
lan358088
发表于 2018-3-29 12:01:00
def newlist(n):
new=[]
x = 1
for i in range(1,n+1):
new.append(i)
if new==[]:
print(new)
while new!=[]:
print(new[:x])
for i in new[:x]:
new.remove(i)
x+=1
newlist(12)
达锅
发表于 2018-3-29 12:09:46
def main(n):
mli,n=list(range(1,n+1)),0#生成列表以后n的值就不是原来的n了,懒得换变量了
while mli:#每次迭代都会缩短原来的列表,只要判断n之后没有数据,就可以返回了
mli=mli[:n]+]+mli#公式分头尾和中间,中间按照题意,把n个数合成列表,每次修改第n个数,第一个有一个数,第二个有二个数,所以是2*n+1。头为保留前n-1个数不变,尾第n个数修改以后,中间的数不再保留
n+=1
return mli
for i in range(12):
print(i,main(i))
这道题我喜欢,目测代码应该是最短的了,早上刚看到,虽然超过时间了,也给点奖励吧
Pythoner_3.21
发表于 2018-3-29 13:02:11
def newlist(n):
if n :
list1=[]
i=1
s=1
while s <= n:
a=list(range(i,s))
list1.append(a)
i += len(a)
s = i + len(a) + 1
list1.append(list(range(i,n+1)))
del list1
print(list1)
else:
return []
榴莲酱奶昔
发表于 2018-3-29 13:13:11
本帖最后由 榴莲酱奶昔 于 2018-3-29 13:16 编辑
def newlist(n):
result=[]
temp=[]
count=1
for i in range(1,n+1):
temp.append(i)
if len(temp)<count:
continue
else:
result.append(temp[:])
temp=[]
count+=1
if len(temp):
result.append(temp)
return result
else:
return result
whalesea
发表于 2018-3-29 21:14:04
import math
def increment(n):
#print(int((1 + math.sqrt(1 + 4 * n)) / 2) + 1,(1 + math.sqrt(1 + 4 * n)))
#if int((1 + math.sqrt(1 + 4 * n)) / 2) != ((1 + math.sqrt(1 + 4*n))/2):
# k = int((1 + math.sqrt(1 + 4*n))/2) + 1
#else:
# k = ((1 + math.sqrt(1 + 4*n))/2)
#print(k)
k = int((1 + math.sqrt(1 + 4 * n)) / 2) + 1
print(k)
lst =
print(lst)
result = []
for i in range(1,int(k)+1):
k1 = int(i * (i - 1) / 2)
k2 = int(i * (i + 1) / 2)
print(k1,k2)
print(lst)
result.append(lst)
print(result)
nanayuri
发表于 2018-3-30 16:10:01
def newlist(n):
l =
list_n = []
list_t = []
for each in l:
length = len(list_t)
if length > 0:
max_num = 0
for i in range(1, length + 2):
max_num += 1
if len(list_n) < max_num:
list_n.append(each)
if each == l[-1]:
list_t.append(list_n)
else:
list_t.append(list_n)
list_n =
if each == l[-1]:
list_t.append(list_n)
else:
if each > 0:
list_n =
list_t.append(list_n)
list_n = []
else:
list_t = []
return list_t
print(newlist(2))
秋之临
发表于 2018-4-1 13:49:16
def newlist(n):
a=[]
k=1
for i in range(1,n+1):
b=
a.append(b)
if n<k:
break
k=k+i
if n<k:
break
return a
print(newlist(14))
print(newlist(15))
print(newlist(16))
print(newlist(17))
print(newlist(18))
print(newlist(19))
print(newlist(20))
print(newlist(21))
print(newlist(22))
端木
发表于 2018-4-1 16:19:24
import math
def newlist(n):
new_list = []
if n == 0:
return new_list
layer = int(math.ceil(math.sqrt(2*n) - 0.5))
n_list =
for i in range(1, layer+1):
if n >= sum(range(i+1)):
new_list.append(n_list)
else:
new_list.append(n_list)
return new_list
print(newlist(16))
soonGy
发表于 2018-4-2 15:13:42
def dimension(number):
lista =
flag = 0
while number > flag:
number -= flag
flag += 1
xflag = 1
x = 0
while flag > 0:
y = x + xflag
print(lista)
flag -= 1
xflag += 1
x = y
return
number = int(input())
while number > 0:
dimension(number)
number = int(input())
a690089735
发表于 2018-4-2 18:29:36
新手挑战一下每日一题,只想到了这种思路
def x1(n):
if n:
listn = list(range(1,n+1))
i = 0
while not i>=n:
l = listn
j = 0
for k in range(1,5):
yield l
j+=k
i += 10
else:
return []
def newlist(n):
return list(filter(lambda i:i,x1(n)))
print(newlist(10))
print(newlist(0))
hxgoto
发表于 2018-5-6 21:04:11
def newlist(n):
if n == 0:
return []
ls = []
if n >= 1:
count = 1
lst = []
for i in range(1,n+1):
lst.append(i)
if count == len(lst):
count += 1
ls.append(lst)
lst = []
else:
ls.append(lst)
return ls
print(newlist(12))
夏未至夜未央
发表于 2018-6-22 09:42:36
def newlist(n):
if n == 0:
return new_list
elif n < 0 :
print('Wrong!')
else:
list1 =
num = 0
for i in list1:
new_list.append(list1)
num = num + i
if list1[-1] == new_list[-1][-1]:
break
return new_list
new_list = []
n = int(input('n='))
print(newlist(n))
子沙
发表于 2018-10-3 17:43:37
def fun_172(n):
def x(i):
return int(i*(i+1)/2)
list1=
list2,i=[],1
while x(i)<n:
list2.append(list1)
i+=1
list2.append(list1)
return list2 if n>0 else []
print(fun_172(10))
kinkon
发表于 2022-9-7 10:11:32
本帖最后由 kinkon 于 2022-9-7 10:14 编辑
def newlist(n):
res = list()
ans = list(range(1, n + 1))
i = idx = k = 0
while idx <= n:
k += 1
res.append([])
res[-1].extend(ans)
i += 1
idx += i
while res and not res[-1]:res.pop()
return res
for i in range(21):
print(newlist(i))