n=int(input())
z = int(input('Введите количество цифр в строке:')
i = 1
while i <= n:
if i != 0:
if i%z == 0:
print(i, end=', \n')
else:
print(i, end=', ')
i += 1
n, c, i = int(input()), int(input()), 1
while n >= c:
print(', '.join([str(i) for i in list(range(i, i + c))]), end = ',\n' if n - c != 0 else '')
n -= c
i += c
print(', '.join([str(i) for i in list(range(i, i + n))]))
像这样试试
N - 要分成几行的数字
C - 每行的数字数量
好吧,或者像这样 - 一个常规循环,加上一个三元运算符两次以了解在行尾打印什么: