The following happens in my mind: ans makes 2 recursive calls (n = 7 and n = 6) each of these two make two more calls etc etc till all these calls end with an n of 2 or 1.
You need to be more strict about your logic here. First of all ans is a variable. So saying "ans makes 2 recursive calls" is nonsense. Also, the line with the recursive calls is inside the else block of an if statement, so you need to evaluate the condition of the if to determine whether or not a recursive call even happens.
So let's analyze this more thoroughly for fib(7). Since 7 is not a key in the dictionary, we make a recursive call to fib(6). This in turn calls fib(5) and so on until we get to fib(2). Let's represent each recursive call with indentation:
fib(7)
fib(6)
fib(5)
fib(4)
fib(3)
fib(2)
Now we get to a point where the if condition is True because the dictionary has 2 as a key. So and fib(2) returns 2. Let's note that with ->
fib(7)
fib(6)
fib(5)
fib(4)
fib(3)
fib(2) -> 2
Now fib(3) calls fib(n - 2) which is fib(1). And fib(1) returns 1. We just add this with the appropriate level of indentation:
fib(7)
fib(6)
fib(5)
fib(4)
fib(3)
fib(2) -> 2
fib(1) -> 1
Now fib(3) adds the result of 2 + 1 to the dictionary and returns:
fib(7)
fib(6)
fib(5)
fib(4)
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
Now we are at the fib(4) level, which calls fib(2) and which returns 2:
fib(7)
fib(6)
fib(5)
fib(4)
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
And now fib(4) returns 3 + 2:
fib(7)
fib(6)
fib(5)
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
Now we are back at the fib(5) call which calls fib(n - 2) or fib(3):
fib(7)
fib(6)
fib(5)
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
fib(3)
But we already called fib(3) and stored its value in the dictionary. So this returns immediately without any additional recursive calls:
fib(7)
fib(6)
fib(5)
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
fib(3) -> 3
And now fib(5) returns 5 + 3:
fib(7)
fib(6)
fib(5) -> 8
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
fib(3) -> 3
Now we are back at fib(6) which calls fib(4). Again, we have already calculated this and its result is returned immediately:
fib(7)
fib(6)
fib(5) -> 8
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
fib(3) -> 3
fib(4) -> 5
Now fib(6) returns 5 + 8:
fib(7)
fib(6) -> 13
fib(5) -> 8
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
fib(3) -> 3
fib(4) -> 5
And we are back at fib(7) which calls fib(5) next. Again, we have already calculated this value and stored it, so we return immediately:
fib(7)
fib(6) -> 13
fib(5) -> 8
fib(4) -> 5
fib(3) -> 3
fib(2) -> 2
fib(1) -> 1
fib(2) -> 2
fib(3) -> 3
fib(4) -> 5
fib(5) -> 8
And finally fib(7) returns 13 + 8 or 21.
As you can see there are 11 recursive calls for fib(7). I let you do the rest of the analysis for fib(8).
d[n] = ansstep), you get 41 calls to the function.