【用代数讲计算机科学】操作符运算顺序 – 译学馆

• #### 科普

SCIENCE

#### 英语

ENGLISH

#### 科技

TECHNOLOGY

MOVIE

FOOD

#### 励志

INSPIRATIONS

#### 社会

SOCIETY

TRAVEL

#### 动物

ANIMALS

KIDS

#### 卡通

CARTOON

#### 计算机

COMPUTER

#### 心理

PSYCHOLOGY

#### 教育

EDUCATION

#### 手工

HANDCRAFTS

#### 趣闻

MYSTERIES

CAREER

GEEKS

#### 时尚

FASHION

• 精品课
• 公开课
• 欢迎下载我们在各应用市场备受好评的APP

点击下载Android最新版本

点击下载iOS最新版本 扫码下载译学馆APP

#### 【用代数讲计算机科学】操作符运算顺序

CS in Algebra: Order of Operations

You may have noticed the evaluation block only has two slots.

What if I want to add 1 plus 2 plus 3?

Think of each of these slots as an input.

Each input on an evaluation block can take a value, like 1 or 2.

But they can also take a whole other evaluation block.

To add 1 plus 2 plus 3, we can drop in an additional block for 2 plus 3.

When the computer evaluates your blocks, it starts from the inside out, evaluating each

nested block before it moves out to the next level.

This brings us to the order of operations.

Operations are actions, such as add, subtract, multiply and divide.

If it isn’t a number, it probably is an operation.

But when you see something like 7 plus 6 times 52 plus 3,

which part should you calculate first?

Do you start at the left and go to the right?

Or start at the right and go to the left?

This actually matters because calculating in the wrong order will get you a wrong answer.

There is a specific order of operations

that tells you what to do first and then to do next.

We can remember the order with a cool word called PEMDAS:

Parentheses, Exponents, Multiplication, Division, Addition and Subtraction.

Do things in parentheses first: 6 times 5 plus 3 turns into 6 times 8 which equals 48.

If we just went left to right and did 6 times 5 and got 30 and then added 3, that would

equal 33 which is wrong.

After we’ve done parentheses, we move on to exponents.

In this example, we square the 2 first and then multiply it by 5 to get 20.

Next is M and D for multiply and divide.

Anywhere in your expression that has a multiply or divide sign needs to be done before addition

or subtraction.

If there is multiply and divide in the same expression, then just go left to right.

Again, PEMDAS stands for: P – Parentheses first, E – Exponents next, then M, D – Multiplication

and Division which is done left to right and finally A, S – for Addition and Subtraction

which is also done left to right.

Divide and Multiply rank equally and go left to right.

Add and subtract rank equally as well and go left to right.

You can remember PEMDAS with a few fun phrases like Please Excuse My Dear Aunt Sally or Pudgy

Elves May Demand A Snack or even Please Eat Mom’s Delicious Apple Strudels.

Your computer isn’t smart enough to understand order of operations.

You need to show it the order you want operations to be done in.

We can do that by nesting blocks inside of other blocks.

Blocks are evaluated from left to right and from the inside out.

If we wanted to program the expression 8 minus 2 times 5 plus 10 divided by 2 plus 1, we

can use PEMDAS to remember the order we should nest our blocks in.
P-这里并没有圆括号 所以略过
P – there are no parentheses so let’s move on.
E-也没有指数
E – no exponents either.

Next Multiplication – M. Ok, so we have some multiplication.

Let’s make a block for the 2 times 5.
D-这里也有除法
D – there’s also some division too.

Let’s make a block for 10 divided by 2.
AS-这里也有加法和减法 因此我们从左到右挑出它
A, S – we’ve also got addition and subtraction here so let’s sort it out from left to right.

First we can grab a subtraction block and plug in 8 on the left and our 2 times 5 block
2×5的单元框
on the right.

Then we’ll grab an addition block, plug in our whole 8 minus 2 times 5 expression on

the left and another addition block on the right.

Then finally we can plug in our 10 divided by 2 on the left side and 1 on the right.
8-2×5+10÷2+1
8 minus 2 times 5 plus 10 divided by 2 plus 1.

And that’s it!

The block version of this mathematical expression.