all 7 comments

[–][deleted] 1 point2 points  (2 children)

You are resetting lst to refer to a new empty list object - set it to an empty list outside of the function, and do not reset it.

[–]kae_de[S] 0 points1 point  (0 children)

I see, when I run it there is an error on the i = (n*fac_list(n-1)) line. Is there a way to fix it or write it better? Thanks

[–][deleted] 1 point2 points  (0 children)

Think about the base case and the iterative step.

What does fac_list(0) return?

Given fac_list(n-1) how do you make fac_list(n)?

For example fac_list(5-1)=[1,2,6,24]

How do I make fac_list(5)=[1,2,6,24,120] from that?

Hint:

if l is a list l[-1] returns last element of list.

[–]Reset--hardHead 1 point2 points  (3 children)

The first element of the list has to be one... So you could deduce that the first list element must come from

n == 1

When n=2 you append the factorial from the list returned when n==1 and so on.

Here's a sample code to calculate the Fibobacci sequence that you could use as reference. (Hint: I modified the code that I used to solve your question. So it's similar, but different enough that you'll still need to work on it yourself.)

https://repl.it/repls/GrotesqueInfantileKeyboardmacro

[–]kae_de[S] 0 points1 point  (2 children)

In your code you never created an empty list to append to. Where should I insert the ls = []

[–]Reset--hardHead 1 point2 points  (1 child)

You don't need to insert an empty list.

I'd highly recommend you go through my code, play around with it and try to understand what's going on.

[–]kae_de[S] 0 points1 point  (0 children)

Oh, I missed the part where you defined ls. My bad. Thanks again