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

Chandelor Simon
Chandelor Simon
2,242 Points

PEMDAS Clarification?

P - Parenthesis E - Exponents M - Multiplication D - Division A - Addition S - Subtraction

Under these guidelines, the equation: 10 - 3 * 5 + 8 should be resolved in this order:

3*5, 15+8, 10-23

correct? Except - obviously I'm wrong lol; can someone explain this to me?

You can use BODMAS as well cause they teach BODMAS instead or PEMDAS in a lot of countries.

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Adam Pengh is correct. You work the PEMDAS but do it left to right.

However, it may be easier to remember that it is just an Acronym to remember the basic order. In actuality, the Parenthesis and Exponents are equal in precedence - the Multiplication and Division (and Modulo as well) are equal - and the Addition and Subtraction are equal. So PEDMAS could also be EPMDSA.
The former is taught only because it can be remembered by the mnemonic "Please Excuse My Dear Aunt Sally"

Hope that helps to clear it up for you. :) :dizzy:

Chandelor Simon
Chandelor Simon
2,242 Points

That's perfect - thank you both for the guidance!

Hanneke Lu
Hanneke Lu
560 Points

Addition and substraction are equal in terms of order. So then, the left-to-right way of working determines which one is executed first. But. In this equation there's also a multiplication, so that has to be executed first.

(Think about it like three levels: First: Parenthesis and Exponants Then: Multiplication and Division Last: Addition and Substraction

When working 'within a level', the one that comes first when reading from left to right, has priority)

I think Jason Anders explanation was great, but since your question was asked after his explanation, I assume it didn't work for you. Hope this helped.)

Adam Pengh
Adam Pengh
29,881 Points

You still have to work left to right, so 10 - 3 * 5 + 8 reduces to 10 - 15 + 8. Then 10 - 15 = -15, -15 + 8 give you -7. If you do 10 - 23, you get -13.

Chandelor Simon
Chandelor Simon
2,242 Points

So - left to right trumps addition over subtraction? If this is so, why not start with 10-3? What is the use of PEMDAS?

Gideon De Villiers
Gideon De Villiers
Courses Plus Student 632 Points

So I hope I can clarify with my limited knowledge, but my understanding is that the order of operations (PEMDAS) takes place and then the left to right flow is applied. So in the example: 10 - 3 * 5 + 8. Let's take out parenthesis, exponents, and division because they're not applicable. We're left with MAS. Multiplication, Addition, and Subtraction. The multiplication happens first. So we're left with 10 - 15 + 8. As Adam pointed out addition and subtraction are equal so we just flow left to right. 10 - 15 = -5. -5 + 8 = 3. Hope that helps!