+ 1

Trying to print all prime number within a particular range

https://code.sololearn.com/cu20g5YsV8Uj/?ref=app

8th Jun 2019, 1:27 PM
Pattanaik Bhupesh
Pattanaik Bhupesh - avatar
6 odpowiedzi
+ 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
8th Jun 2019, 2:03 PM
Airree
Airree - avatar
+ 2
Thanks ...well I could not understand the problem 2 explaination 😅
8th Jun 2019, 2:06 PM
Pattanaik Bhupesh
Pattanaik Bhupesh - avatar
+ 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")
8th Jun 2019, 2:10 PM
Airree
Airree - avatar
+ 2
Thanks... 👍
8th Jun 2019, 2:10 PM
Pattanaik Bhupesh
Pattanaik Bhupesh - avatar
+ 1
I think you can not do it,because there are lot of prime numbers!
8th Jun 2019, 2:26 PM
CodeFu
CodeFu - avatar
0
Codinger .... I am trying to print just some prime numbers only (like all prime numbers less than 100)
8th Jun 2019, 3:23 PM
Pattanaik Bhupesh
Pattanaik Bhupesh - avatar