FAQ: Operators - Putting it All Together

This community-built FAQ covers the “Putting it All Together” exercise from the lesson “Operators”.

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

Learn How To Code

FAQs on the exercise Putting it All Together

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!

2 Likes

Here, I’m coding “oranges = oranges - 2”. Isn’t that impossible, defining something with itself? That would mean that every time I code in “oranges”, it takes the previous oranges and subtracts 2 from that, right? How does a computer get around that logical problem?

Thanks!

4 Likes

I believe so. Essentially, you’re saying I would have to assign a new variable to equal the “orange - 2”.

A question: what would happen if you didn’t do so? Essentially doing this:

// Create an orange variable and set it to 4

orange = 4;

// Decrease the amount of oranges from 4 to 2

orange = orange - 2;

What would the program reader do then?

2 Likes

You may be able to find a better explanation, but think of your variable orange as a container like a basket or bag. It’s simply a named memory location holding a value. When you declare orange = 4 you’ve put the value 4 into your bag. For the sake of this example, let’s say you have four oranges in the bag. When the computer reads your line orange = orange - 2 the position of the = makes a difference. The orange on the left side is waiting to be assigned a new value. The new value will be determined by what’s on the right side. The orange on the right is not the memory location itself or the bag. It is the contents of the bag, or value stored in the memory location which in this case is 4. Therefore, you are assigning orange a new value of 4 - 2. Hopefully that made some sense :grinning:

8 Likes

Think of values as objects with a hook on them, and variables as tags that we can hang on those hooks. When the variable is assigned a new value, the current value does not change. Only the hook we hang the tag on does. The new value would likely be in a different location, and the old value will cease to be unless it still has a tag or tags hanging on its hook.

This runs counter to thinking of variables as containers. They are not containers, only names that refer to an object in memory such as a value or a data structure.

3 Likes

Thank you everyone for all your help!

1 Like

Ive inputed orange = 4 and then orange = 4 -2
Two oranges appeared on the screen with 3 apples, but when i tried to continue there was a red circle over the continue button.

@script8041588897, thanks for bringing this up. I’ve gone to the exercise, and there is a bug in this lesson that prevents the Next button from becoming active even after clicking run with the correct code in the code editor. You can continue on by clicking the Get Help icon in the lower right corner, and then clicking on the Solution tab. Then click on Get Code Solution, then on Give me the solution to this exercise. It will refresh the screen, and the Next button will be active. I’ll report this bug to the Codecademy Engineering team. Thanks again, for pointing out this bug.

1 Like

There may be a new bug (or not) my screen now shows only 2 apples alongside the wonderful 2 oranges so, what became of the other apple since it seemed to illogically disappear?!

Thanks @midlinder. I could not get this page to work, gave up and moved on anyway :grimacing:

Sorry @tag1881612833, I hadn’t gotten back to you. I seemed to notice that that numbers of different fruits didn’t necessarily coincide with the lesson, but I’m not sure that’s a bug. I don’t know it they intended it too or not. Hopefully the lessons are functional though.

1 Like

I’ve reported the bug in the lesson, but haven’t had any response other than “they’re working on it.”

1 Like

Just to add: Since the computer reads the code from top to bottom, it will see that your have given the variable oranges a value of 4 and then it sees you change the value on the next line into previous value of orange - 2.

Hello all,
so, since the computer reads from top to bottom, shouldn’t the last value here be 1?

// Create an orange variable and set it to 4
orange = 4

// Decrease the amount of oranges from 4 to 2
orange = orange - 2

// Decrease the amount of oranges from 4 to 2
orange = orange - 1

I’ve entered this and I’m left with no orange at all.
Thanks

Oranges and apples; hmmm.

1 Like

oops i meant I’m left with no orange at all. i’ve edited my previous message for clarity now.

I have entered
orange=4
orange=orange-2

But how about orange=4-2? It it the same? It gives me the same result so I was wondering why we need to type orange if we can type 4-2?

Not the same. We might not know the value of orange is actually 4, only that we wish to increase it by 2.

orange = orange + 2

That’s taking the current value of orange, adding 2 then reassigning the new value back on to the original variable.

Even after clicking on " Get code solution" i am unable to click on button next.
I believe its a bug :frowning_face: