How do order of operations go on Python?

前端 未结 5 1066
庸人自扰
庸人自扰 2020-12-06 06:41

My question looks like this:

  10-7//2*3+1 

I am supposed to solve the equation.

My answer seems to come out as 8 when using PEMDAS:

5条回答
  •  感动是毒
    2020-12-06 07:32

    PEMDAS is better expressed as

    P   Parentheses, then
    E   Exponents, then
    MD  Multiplication and division, left to right, then
    AS  Addition and subtraction, left to right
    

    So in your expression, the division should be done before the multiplication, since it is to the left of the multiplication. After those are done, then do the subtraction then the addition.

提交回复
热议问题