FAQ: Recursion: Python - Building Our Own Call Stack, Part II

This community-built FAQ covers the “Building Our Own Call Stack, Part II” exercise from the lesson “Recursion: Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Recursion: Python

FAQs on the exercise Building Our Own Call Stack, Part II

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Is there a reason to use while n != 1 instead of while n is not 1?

Is there a reason why is not would be suitable? What does that operator do?
You’d need some kind of integrity check there. “Do I know what this promises to do?”

Well, both of them compare is one thing is the same as the other thing, I don’t see any difference. I checked and both of them work when I execute code.

Both of them compare, what do they compare?

One of them tests for equality, the other tests for something else. What?
Either you can answer that, and then tell yourself why you would use one or the other. Or you can’t, and then you shouldn’t be using it (at least not without first finding out what it does)
What you shouldn’t be doing here is expecting them to do the same thing.

The way you go about programming is picking out different components, being aware of what they promise to do so that you can combine them to get your overall result.
If you don’t have those promises then you’ve got nothing, so you always have to have some awareness of how well you know the thing you’re using.

I’m not saying you shouldn’t use new things or shouldn’t experiment, but the expectation of “this should work/do the same thing” is … not based in something reliable.

So my suggestion is to ignore that operator because you don’t know what it does and have no use for it at the moment, same as you would ignore lots of other features you haven’t gotten around to yet.
Or if you can’t let it go, then the first attempt for answering pretty much every question is to do a web search. Being an operator, it should be easy to find out what it does.

1 Like

This is the exercise:

def sum_to_one(n):
result = 1
call_stack =

while n != 1:
execution_context = {“n_value”: n}
call_stack.append(execution_context)
n -= 1
print(call_stack)
print(“BASE CASE REACHED”)
return result, call_stack

sum_to_one(4)

My question: in the line:
execution_context = {“n_value”: n}

how come the string “n_value” change to “4_value”, “3_value”, etc, and does not remain as “n_value”?
Tjis is a simple string after all!
My guess would be that it takes an expression like “{}_value”.format(n) to evaluate to “4_value”, “3_value”, etc?

Amikam

I understand that the question was made too much time ago, but as I was also a little confused…
“n_value” is a string and it doesn’t change from value to value of n. Think of it like of a frase “our n has now a value” : n
(which takes it’s respective value)
seems it’s better to write it without the underscore…

in this line of code from the exercise:

print(“Return value of {0} adding to result {1}”.format(return_value[‘n_value’], result))

where do 0 and 1 come from? what do they represent?