Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Need explanation.

+4 votes
asked Oct 7 by JustAnAcc (790 points)
Hi! I'm an 11 year old programmer, who started in may. I code with python. I copyed a program, that tells you 3's multipliers (Sorry for my spelling). Can somebody tell me why is the "+1" at the for loops? Thanks.

https://onlinegdb.com/HLSbj-q69e

2 Answers

0 votes
answered Oct 8 by YuLinLee (140 points)

range(start, stop, step)

ParameterDescription
startOptional. An integer number specifying at which position to start. Default is 0
stopRequired. An integer number specifying at which position to stop (not included).
stepOptional. An integer number specifying the incrementation. Default is 1
+1 vote
answered Oct 8 by Peter Minarik (63,140 points)

It's always a good idea to check out some documentation if you're unsure how a funciton or class works. For instance, check out the range().

You can see that range(start, stop, step) has 3 arguments: start, stop and step. The first element is start, but stop is never actually reached. Hence if you do want stop to be reached, you need to provide a new end, hence the writer of the code did stop + 1.

I hope this helped.

commented Oct 8 by JustAnAcc (790 points)
Thank you so much!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...