在 python 中打印逻辑顺序

printing logical sequence in python

我的程序读取两个数字 X 和 Y (X < Y)。在此之后,它显示 1 到 Y 的序列,传递到下一行到每个 X 数字。

我的代码:

x, y = map(int, input().split())
count = 0
a, b, c = 1, 2, 3

while count < (y//x):
    print('{} {} {}'.format(a, b, c))
    a += d
    b += d
    c += d
    count += 1

示例输入:

3 99

我想要的输出:每个序列必须打印在一行中,每个数字之间有一个空白space,如下例

1 2 3
4 5 6
7 8 9
10 11 12
.....
....
97 98 99

你必须使用两个循环,代码如下所示:

x, y = map(int, input().split())
count = 0

while count < (y//x):
    start = count*x + 1
    end = (count + 1) * x + 1
    for i in range(start,end,1):
        print(i,end=" ")
    print("")
    count+=1

您可以使用范围生成 y 个数字的列表,然后您可以在 x 个块

中迭代它
def print_lines(x, y):
   nums = list(range(y))
   for i in nums[::x]:
      print(" ".join([str(num + 1) for num in nums[i:i + x]]))

print_lines(3, 99)