Python3-Q2 | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Python3-Q2

Why this code: for i in range(10): if not i % 2 == 0: print(i+1) it has this output?

2nd Jul 2018, 6:24 PM
Ali shayani
3 Antworten
+ 5
The if statement is true for odd numbers as i%2 == 0 is true for evens and not false is true. The print adds one to i so will be display the next higher even.
2nd Jul 2018, 6:48 PM
John Wells
John Wells - avatar
+ 4
What output? amirhossein jamazari please sate the output.
2nd Jul 2018, 6:27 PM
Agent
Agent - avatar
0
output is 2 4 6 8 10
2nd Jul 2018, 6:55 PM
Ali shayani