+ 1
Can someone explain to me step by step? Thanks (:
for i in range(10): if not i%2==0: print(i+1) OUTPUT: 2 4 6 8 10
2 Réponses
+ 3
for i in range(10) means from 0-9.
not % 2 == 0 means all i which are not divisible by 2.
In the end whenever i is odd it prints i+1.
1 -> 2
3 -> 4
5 -> 6
7 -> 8
9 -> 10
+ 4
Yes in for loop , i is 1,2,3,.....,9
And if i is even then nothing is printed as not is used
Then i=1, no. Is odd then i+1 =2 is printed
Then i=2 no is even no result, if condition fails
Then i=3 no. Is odd then i+1=4
Is printed
.
.
.
.
Then i=9 then no. Is odd so i +1=10 is printed