-1
作为一组循环练习的一部分,我应该编写一个读取两个整数X和Y的程序。作为输出,程序打印所有从1到Y的整数,组织成X数字出现在每一行上。在同一行中打印数字
所以我应该在某处使用while
或for
。我至今是:
代码:
n_per_line = int(input('Numbers per line: '))
upperbound = int(input('Upper bound: '))
i = 1
n = 1
while i <= upperbound:
while n <= n_per_line:
print(i, end=' ')
n += 1
i += 1
然而,这仅仅打印出一个输出线。例如,
Numbers per line: 3
Upper bound: 4
gives 1 2 3 in a single line. And
Numbers per line: 2
Upper bound: 4
gives 1 2 in a single line.
你有任何的代码? –
请在问题中键入您的代码作为文本,而不是显示它的图形。从文本编辑器复制并粘贴到您的问题中,突出显示代码,然后单击“{}”按钮,以便将其格式化为文本。 –