+ 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)
7 Antworten
+ 5
here is my try, printing in rows is done with a for loop:
https://code.sololearn.com/cn67fM1BNQR7/?ref=app
+ 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.
+ 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=' ')
+ 1
print(num, end=' ')
+ 1
thanks, but It doesn't work
+ 1
do you have good indentation on the program?
+ 1
Yeah