+ 1
Trying to print all prime number within a particular range
6 Respuestas
+ 3
Problem 1: In the for loop, you don't need to add 1 to i, since it is incremented auromatically
Problem 2: This is not how prime numbers work. You have to divide it by all numbers smaller than it, count how much of them is divisible by it, if it's 1, then the number is 1, if it's 2, it's a prime, if more, it's not a prime
+ 2
Thanks ...well I could not understand the problem 2 explaination 😅
+ 2
for i in range(1, x):
for n in range(1, i):
count = 0
if i % n == 0:
count += 1
if count == 1:
print(str(i) + ": One")
elif count == 2:
print(str(i) + ": Prime")
else:
print(str(i) + ": Non-Prime")
+ 2
Thanks... 👍
+ 1
I think you can not do it,because there are lot of prime numbers!
0
Codinger .... I am trying to print just some prime numbers only (like all prime numbers less than 100)