0
There is a "for" loop to get even values
for i in range(0,20,a): print(i) when a=2, we can get event values. However,when a=4,6 or 8, the loop can not be ran to get event values, why?
5 ответов
+ 1
When the incrementing number is 4 or 6, you won't be getting ALL of the even values anymore like you do with 2. Instead you will just get the multiples of 4 and 6. The multiples of 2 are all the even numbers, which is why that works
0
in
for i in range(0,20,a):
a refers to the number we want to increment
for e.g.
for i in range(0,8,2): #(here 2 denotes as i=i+2)
print(i)
Output-
0,
2
4
6
6(incrementing everytime by 2)
Also when
for i in range(0,8,4): #here i=i+4
print(i)
Output-
0
4
so, when a=2,
it will return all even numbers
0
You are welcome
0
Thank you very much,Zeke Williams.
- 1
It should be when: a % 2 == 0