Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching Numeric

Question about the PEMDAS formula Craig is explaining

Hey fellow coding students and teachers,

I don't really see how the „PEMDAS“ formula that Craig is presenting in the video is working in his example:

10 - 3 * 5 + 8 = 3

I understand how the result is 3 by calculating

(( 10 - ( 3 * 5 )) + 8 = 3

But according to the „PEMDAS“ formula the addition („A“) would have to be calculated before the substaction („S“).

So if this „PEMDAS“ formula would really be applied it should be:

10 - (( 3 * 5 ) + 8) = -13

Or am I missing something?

Isn't it that addition and substraction are equal and will just be calculated in the order they appear (and not according to the PEMDAS order)?

Would be happy if someone could clear my confusion.

You get an upvote for sure for your answer. :-)

Hambone F
Hambone F
3,581 Points

Another way to think about it :

10 - (3 * 5) + 8
10 - 15 + 8
-5 + 8
3

is really the same as:

10 - (3 * 5) + 8
10 + (-(3*5)) +8
10 + (-15 + 8)
10 + (-7)
10 - 7
3

You can even change the order around so addition happens first:

10 + 8 - 3 * 5
10 + 8 - (3 * 5)
10 + 8 - 15
18 - 15
3

The order of addition and subtraction actually doesn't matter at all, they are both considered 'commutative' operations.

I think piece that you were missing here is that the negative sign only applies to the value in the middle, it wouldn't be extended to the 8, even if doing that addition first:

The problem with this one is you have actually flipped the sign of the 8 when doing that operation and changed the value, not just did the operation first , even though it may not be obvious - if we have some fun with the distributive property, it should be clear this really is a different equation:

10 - (( 3 * 5 ) + 8)
10 + ((-1) * ((3 * 5) * 8))
10 + (-1)*(3*5) + (-1)*(8)
10 - 3*5 - 8
10 - 15 - 8
-5 - 8
-13

5 Answers

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

Isn't it that addition and substraction are equal and will just be calculated in the order they appear (and not according to the PEMDAS order)?

Yes (MD and AS are equal and processed left to right)

Below is from Math is Fun

P - Parentheses first E - Exponents (ie Powers and Square Roots, etc.) MD - Multiplication and Division (left-to-right) AS - Addition and Subtraction (left-to-right)

Divide and Multiply rank equally (and go left to right).

Add and Subtract rank equally (and go left to right)

Thanks Dave!

That's really clear an helpful.

mohan Abdul
mohan Abdul
Courses Plus Student 1,453 Points

Dave StSomeWhere hi, so what you are saying addition and subtraction are equal and will be executed in the order they appear in? please reply I am counting on you.

David O'Mahoney
David O'Mahoney
869 Points

What you have said is very clear, does this mean that what Craig said in the video is incorrect then? As I found this very confusing, he seemed to ignore the rule he had just given to us.

Hi mate!, as far as i know in math u start substraction or addition for the left to the right, if it’s an + from the left u do this first, then the right side.

addition and substraction are equal , but u add or substract by which come first from the left side. first the (), than * /, and only then + - - this is the priority.

if this help mark as best answer

Thanks a lot, mate!

mohan Abdul
PLUS
mohan Abdul
Courses Plus Student 1,453 Points

David O'Mahoney, I think addition and subtraction are equal to each other, but I depends on what has been entered first. go into repl and swap the plus and subtraction around. So I.e put your ''' 10 - ''' at the end and your '''+ 8''' at the beginning. You'll soon get your answer, I also find that learning from tutorial videos that tracing steps Is a good way to try to understand what you are not getting.

8 + 3 * 5  - 10 = ?
christian garea
christian garea
2,641 Points

Thanks for asking this I had the exact same question he should of explained this

I guess we can agree PEMDAS needs a facelift....(PE)(MD)(AS)