0

How to write these prime numbers 8 per a line?

for Number in range (1, 10001): count = 0 for i in range(2, (Number//2 + 1)): if(Number % i == 0): count = count + 1 break if (count == 0 and Number != 1): print(" %d" %Number, end = ' ') It comes 10 prime numbers per a line but i want to print 8 per a line .how can i code for this?

28th Apr 2020, 11:02 AM
sumaiya sharmin
sumaiya sharmin - avatar
5 Respuestas
+ 4
Sorry, I chose the wrong number. 😅 Forgot to change it when copypasting.
28th Apr 2020, 12:04 PM
HonFu
HonFu - avatar
+ 2
Does this helps? lower = 2 upper = 1000 print("Prime numbers between", lower, "and", upper, "are:") count=0 for num in range(lower, upper + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num,end=" ") count+=1 if count>=8: print("") count=0
28th Apr 2020, 11:13 AM
Abhay
Abhay - avatar
+ 1
This would be my modification. count = 0 for Number in range (2, 10001): for i in range(2, (Number//2 + 1)): if(Number % i == 0): break else: count = count + 1 print( " %d" %Number, end = ' ' if count%5 else '\n' )
28th Apr 2020, 11:22 AM
HonFu
HonFu - avatar
0
Oh that's it. thanks 😊 i tried by this way before
28th Apr 2020, 11:19 AM
sumaiya sharmin
sumaiya sharmin - avatar
0
But it will print 5 numbers per line.we can use various numbers as we want.thank you 😊
28th Apr 2020, 11:29 AM
sumaiya sharmin
sumaiya sharmin - avatar