0

Can someone pls explain how this code works ?

for no in range (1, 10): if no % 2 == 0: print (no) this code prints 2,4,6,8 how ?? can't understand no means numbers

6th Aug 2019, 8:32 AM
R. Krishna
3 Answers
+ 3
'no' is the index that can take values from 1 to 9. if condition checks whether value of index 'no' is even using '%- Modulus' operator. 2,4,6,8 are the even numbers in the range 1 to 9. Hope this helps...
6th Aug 2019, 8:55 AM
Kuri
Kuri - avatar
+ 1
Line 1 shows that it loops from numbers 1 to 10 Line 2 checks (using the modulo operator), if that iteration's number is even Line 3 prints that number if it is even
6th Aug 2019, 8:51 AM
Trigger
Trigger - avatar
0
Thank u
6th Aug 2019, 8:52 AM
R. Krishna