Creating a list of numbers containing 1 to 10 using the range() function and/ or a for loop
python range and for loop understanding - Stack Overflow
Python: for i in range (1, 10), print (i). Why does it not print the number 10?
Print numbers 1 to 10 using a for loop.Give me a detailed correct answer
Videos
How does one create a list of numbers containing 1 to 10 using the range() function and/ or a for loop?
I’m expected to get [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
When you call range() with two arguments, the first argument is the starting number, and the second argument is the end (non-inclusive). So you're starting from len(list_of_numbers), which is 5, and you're ending at 6. So it just prints 5.
To get the results you want, the starting number should be 0, and the end should be len(list_of_numbers)+1. If you call it with one argument, that's the end, and 0 is the default start. So use
for i in range(len(list_of_numbers)+1):
or if you want to pass the start explicitly:
for i in range(0, len(list_of_numbers)+1):
range gives you and iterator between (start, end) end not included.
So in your case the iterator is (start=len(list_of_numbers), end=6).
Since len(list_of_numbers) = 5, this translates to range(5,6) which is 1 element, 5, since 6 is excluded.
https://docs.python.org/3/library/functions.html#func-range
I talked with my data science tutor for almost 20 minutes and he couldn't give me an answer beyond: "It just doesn't give you the last value. It's just something you remember."