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
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...
+ 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
0
Thank u