+ 1
I have a code to print all the prime numbers upto a given limit which user inputs. Its not working. What's wrong?
6 Answers
0
It's input() not input
Also you haven't defined num
0
Sorry that's the wrong code đ
. Check again
0
Ok
0
Did you checked how it works?
If input is 5
For i=2
It's 2%2!=0
which is false
Then for i=3
It's 3%2!=0 which is true
But 3%3 is 0 which is false
Same for i=4
But for i=5
It's 5%2!=0
5%3!=0
5%4!=0
So it is true and only answer is 5
List comprehension isn't good for readability as well as your own understanding first try to solve it through loops and if else then implement it as list
0
If a number gets divided by 2 or 3 it isn't a prime number
And that's what I did
[i for i in range(2,x+1) if i%2!=0 and i%3!=0 or i/2==1 or i/3==1 ]