+ 1

I have a code to print all the prime numbers upto a given limit which user inputs. Its not working. What's wrong?

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

7th May 2020, 11:35 AM
Kaushik Nandan
Kaushik Nandan - avatar
6 odpowiedzi
0
It's input() not input Also you haven't defined num
7th May 2020, 11:39 AM
Abhay
Abhay - avatar
0
Sorry that's the wrong code 😅 . Check again
7th May 2020, 11:41 AM
Kaushik Nandan
Kaushik Nandan - avatar
7th May 2020, 11:41 AM
Kaushik Nandan
Kaushik Nandan - avatar
0
Ok
7th May 2020, 11:41 AM
Abhay
Abhay - avatar
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
7th May 2020, 12:00 PM
Abhay
Abhay - avatar
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 ]
7th May 2020, 12:16 PM
Abhay
Abhay - avatar