FAQ: Operators - Putting it All Together

I belive i’ve entered the correct code but no orange ap(pear) :smile:

orange = 4
orange = orange - 2

Now, is this below also a correct solution ?

orange = 4
orange = orange / 2

Nevertheless the number of apples displayed is correct.

Not really. We are told to subtract (take away) 2 from the number of oranges. It is only coincidental that 4 - 2 happens to be the same as 4 / 2. What happens if we have 6 oranges? Subtract 2 and we have 4; divide by 2 and we get 3.

Division and subtraction are not interchangeable operators any more than addition and multiplication are.

Understood.
Thank you for your help !

1 Like

It doesn’t work for me either, nothing comes out on the screen

1 Like

Does anyone other than a bot checks to make sure the exercises work?

1 Like

Each exercise has an accompanying program called a Submission Correctness Test (SCT). There is no test performed by a human if that is what you asking.

This is what I did:

// Create an apple variable and set it to 1

apple = 1

// Increase the amount of apples from 1 to 3

apple = apple + 2

// Create an orange variable and set it to 4

orange = 4

// Decrease the amount of oranges from 4 to 2

orange = orange - 2

What do you mean by different location? Can you be more specific.

instead of thinking of “orange” as a single orange, imagine it means “a bag of 4 oranges” and you are defining that there are 4 oranges in that bag.

but you only need 2 oranges at the moment so you are removing 2 oranges from the bag by instructing " - 2"

1 Like

So I tried using orange = 2 and orange = orange - 2, and both of them worked correctly.
The important part here is to understand the concept.

The concept of representation.

This is how the code might looks like. i = i - 1.

Looks Familiar. right?

Just curious if there’s something wrong with this exercise. I wanted to play around with the variables a bit so I did the following:

apple = 5
apple = apple + 2 (this should resolve to 7 apples)

orange = 5
orange = orange - 2 (this should resolve to 3 oranges)

I get one apple and zero orange. There must be some max number limit or the interface is buggy?

Yes, you should have gotten 7 apples and 3 oranges. The exercise is buggy; I’ve created a post in the Bug Reporting category.