在python中,如何在for循环中一次打印20个元素?

在python中,如何在for循环中一次打印20个元素?,python,Python,在我下面的代码中,我可以确定从ri到rf的极限范围内的素数,并在单独的行中打印每个范围内的素数。但是我找不到一种不使用任何数组或列表就可以每行打印20个素数的方法 import math # inc: increment of the range where the prime number are going to be determine inc = 70 # ri: minimum variable range where the prime number are going to be

在我下面的代码中,我可以确定从ri到rf的极限范围内的素数,并在单独的行中打印每个范围内的素数。但是我找不到一种不使用任何数组或列表就可以每行打印20个素数的方法

import math
# inc: increment of the range where the prime number are going to be determine
inc = 70
# ri: minimum variable range where the prime number are going to be determine
ri = 0
# ri: maximum variable range where the prime number are going to be determine
rf = inc
# rm: maximum range where the prime number are going to be determine
rm = 1000
# z: number of times the program is going to be repeated 
z = math.ceil(rm/inc)

for x in range(z):
    # iteration in the range ri<i<rf "0<i<20"
    for i in range(ri, rf):
        # determine if i is 0 or 1, since they are not prime
        if i > 1:
            # iteration in the range 2<j<i "2<j<3"
            for j in range(2, i):
                # determine if the number is not prime
                if (i % j) == 0:
                    # modulus of i%j " i% [2,3,4,5,....,i]"
                    break
                    # if it is prime break
            else:
                print(i, end=" ")
    # increment the evaluation range of the prime number
    ri += inc
    rf += inc
    # print new line
    print("\n")
导入数学
#inc:确定质数的范围的增量
inc=70
#ri:确定质数的最小变量范围
ri=0
#ri:确定质数的最大变量范围
rf=公司
#rm:确定质数的最大范围
rm=1000
#z:程序将被重复的次数
z=数学单元(rm/inc)
对于范围(z)内的x:

#在riWell范围内的迭代中,您有
print(i,end=“”)
,因此如果运行了20次,它将在一行上结束。也许在break语句和其他打印语句的逻辑上工作添加一个计数器,在素数的每次打印上增加它,如果它达到20,则打印一个换行并将计数器重置为0