Here is my code?
for i in range (10,20,2):
print(i)
The output should be like this
10
12
14
16
18
20
But output is coming:
10
12
14
16
18
Why 20
is not coming?
Here is my code?
for i in range (10,20,2):
print(i)
The output should be like this
10
12
14
16
18
20
But output is coming:
10
12
14
16
18
Why 20
is not coming?
The second argument to range
is exclusive (not included). You would need to set stop
equal to 22
:
for i in range(10,22,2):
print(i)
to have 20
be in the output:
>>> for i in range(10,22,2):
... print(i)
...
10
12
14
16
18
20
>>>
The range
function always prints upto the max val
for i in range (10,22,2):
print(i)
This will print as expected
10
12
14
16
18
20
The maximum value is not included. If you want 20 to appear, you'll need 20+1 as max value.