-5

I tried to calculate the output of this problem in python: 4+6/2 and it was 7 then i reversed them as 6+4/2 and answer was 8. now whats the difference, and why this occurs? what is divided first?

Clark
  • 11

1 Answers1

1

Python uses PEMDAS, as do most languages. Division comes before addition, so it would be calculated as 4+(6/2)=4+3=7, and 6+(4/2)=8. This can be confirmed with any calculator.

PEMDAS is the standard order of operations:

P- Parentheses first

E- Exponents second

M/D- Multiplication or Division third (If there are multiple multiplication or division signs in a row, then operate first to last)

A/S- Addition or Subtraction fourth (If there are multiple addition or subtraction signs in a row, then operate first to last)