Explain this plis | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Explain this plis

for i in range (10): if not i%2==0: print (i+1)

1st Jan 2017, 7:35 AM
stephen haokip
stephen haokip - avatar
1 Resposta
+ 1
for i in range(10): if not i%2==0: print(i+1) result is i=0 #0 divided by 2 leaves a remainder 0 so nothing happens but it goes to the next number i=1 #1 divided by 2 leaves a remainder 1 which is not equal to 0 so the program prints i+1 that is 1+1=2 i=3 #3 divided by 2 leaves a remainder which is not equal to 0 so the program prints i+1 that is 3+1=4 i=4 #4 divided by 2 leaves a remainder 0 so nothing happens but it goes to the next number i=5 #5 divided by 2 leaves a remainder 3 which is not equal to 0 so the program prints i+1 that is 5+1=6 i=6 #6 divided by 2 leaves a remainder 0 so nothing happens but it goes to the next number i=7 #7 divided by 2 leaves a remainder 1 which is not equal to 0 so the program prints i+1 that is 7+1=8 i=8 #8 divided by 2 leaves a remainder 0 so nothing happens but it goes to the next number. i=9 #9 divided by 2 leaves a remainder 1 which is not equal to 0 so the program prints i+1 that is 9+1=10 end the real result is 2 4 6 8 10 #so it prints all the even numbers in the range 0 to 10
28th Jun 2017, 3:27 PM
Ms Arnold
Ms Arnold - avatar