Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在同一行中打印数字_Python - Fatal编程技术网

Python 在同一行中打印数字

Python 在同一行中打印数字,python,Python,作为一组循环练习的一部分,我应该编写一个程序,读取两个整数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 <

作为一组循环练习的一部分,我应该编写一个程序,读取两个整数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

你需要为新的一行打印一张照片

while con1:
    while con2:
        ...
        print(...,end=" ") #this print will put everything in the line
        ...
    print() #make a new line, so any following print use it

您有任何代码吗?请在问题中以文本形式键入您的代码,而不是显示其图形。将文本编辑器中的内容复制并粘贴到问题中,突出显示代码,然后单击
{}
按钮,将其格式化为文本。
a=int(input())
b=int(input())
for i in range(1,b+1):
    print(i,end=' ')
    if i%a==0:print()