Print 20 prime numbers in a row | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Print 20 prime numbers in a row

My project is to print prime numbers between 0 and 1000, but also display 20 of the prime numbers per row. But i was unable to print the numbers on new rows.Could anyone help me with it.Thanks in advance My code is: lower = 1 upper = 1000 print("The prime numbers between", lower, "and", upper, "are:") for num in range(lower + 1, upper + 1): if (num % 2) != 0 and (num % 3) != 0: print(num) elif num//2 == 1: print(num)

21st Aug 2019, 1:04 PM
Earl
7 Answers
+ 5
here is my try, printing in rows is done with a for loop: https://code.sololearn.com/cn67fM1BNQR7/?ref=app
21st Aug 2019, 3:37 PM
Lothar
Lothar - avatar
+ 2
also, i think the logic is wrong. this way you are detecting not multiples of 2 and 3 only. A highly inefficient algorithm to check wether p is prime is to check if p is a multiple of some number less than p, if it is not, p is prime.
21st Aug 2019, 3:36 PM
Bebida Roja
Bebida Roja - avatar
+ 2
Try this n = int(input()) for i in range(1,n+1): if(i>1): for j in range(2,i): if(i%j==0): break else: print(i,end=' ')
22nd Aug 2019, 4:44 AM
Krishnanshu Dey
Krishnanshu Dey - avatar
+ 1
print(num, end=' ')
21st Aug 2019, 2:28 PM
just trying to think
just trying to think - avatar
+ 1
thanks, but It doesn't work
21st Aug 2019, 3:18 PM
Earl
+ 1
do you have good indentation on the program?
21st Aug 2019, 3:26 PM
Bebida Roja
Bebida Roja - avatar
+ 1
Yeah
21st Aug 2019, 3:29 PM
Earl