+ 2

How to generate prime numbers in python using for loop in an interval with explanation starting from number 2 to max

18th Jun 2019, 5:52 AM
Shelly Kapoor
Shelly Kapoor - avatar
3 ответов
+ 2
https://code.sololearn.com/cGT60z1q9qnw/?ref=app here is code but I don't understand 2nd for loop how it print 2,3 because for i in range(2,2) don't work
18th Jun 2019, 7:53 AM
Shelly Kapoor
Shelly Kapoor - avatar
+ 2
@choe else is outside for loop You mean to say that i is nothing so it will print 2
18th Jun 2019, 2:58 PM
Shelly Kapoor
Shelly Kapoor - avatar
+ 1
when num is 2, i is nothing. Nested loops cant output these values, but the else on the loop is what is printing 2 since your condition inside wasnt satisfied. for num in range(lower,upper+1): for i in range(2,num): if(num%i==0): break else: print(num) this should give you something different.
18th Jun 2019, 1:07 PM
Choe
Choe - avatar