Thank you. I’ll look into it and try it out.
I want to make sure I can label the numbers each with a label of 1+ whatever the last number was.
Like I need for sure to put the first number in the list stored next to a number 1.
The second stored next to a number 2.
Ultimately, I need the numbers stored so I can work with them.
For instance, continuing what I began…
153 - 2 = 151 so store 151 first in the list
Then “add the first number in the list with its list number”.
Then “add the second number in the list with its list number”…
IF 151 was the first number in the list it gets 1 as its list number
=so it spits out 152.
IF 149 was the second number in the list it gets 2 as its list number
=so it spits out 151, etc…
Way to do this?
Although (as pointed out) Python uses ‘zero indexing’, you can force an index to start at 1, by using enumerate(), which is one of the many ‘builtins’. e.g: enumerate(N_instance, start=1)
By using that in a for index... loop, you can add the value of index (which will be incremented by 1 with each iteration of the for loop) to every value in the N_instance list.
If you don’t understand what I mean or need help, then post back and say as much. I can post the working code for you, but it would be better for you to at least try, as you’ll learn more by working this out for yourself.
I’d really like to see you to try this for yourself.
Start with:
N = 153
N_instance = []
and think about what you need to do next. Hint: you’ll need a loop that appends the value of N to the N_instance list, while ever N is greater then zero.
Once you’ve got that part sussed, you can move on to the next part.
One example often used with a similar factorial implementation is to use @cache and to use arguments to allow for recursive usage.
Edit: coming back to this at a later time, though maybe too complex for the original poster. I often try to use itertools to help improve performance. You could also change how you go about the solution, use a generator and then use accumulate to get the same result as proposed by others.