Last answered:

03 Nov 2021

Posted on:

03 Nov 2021

0

why we are entering num_2+1 and num_1+1 in for loop code

num_2+1 and num_1+1
in for loop why we are using 1+1,2+1

1 answers ( 0 marked as helpful)
Instructor
Posted on:

03 Nov 2021

0

Hey Satthya,

Thank you for your question!

The reason we are adding one is because of how the range() function works. Imagine that you want to print the numbers from 1 to 10, including 10. If I attempt to do that with range(1, 10), I will get the following output:
image.png
What I need to do to output 10 as well is to add 1 to 10 as follows:
image.png

Therefore, if we want to include the numbers num_1 or num_2, we need to add one in the range() function.

Hope this helps!

Kind regards,
365 Hristina

Submit an answer