[ERT ICT Teaching] Learning Python for JSS (12 - More on assignment statement)

preview_player
Показать описание
A complete series of learning python and computational thinking.
Simple enough for junior secondary school students in Hong Kong.
Рекомендации по теме
Комментарии
Автор

Script:


Hi everyone, I'm Mr. Eric Tang.

The objective of today is to learn the meaning of the statements here. Same suggestion as before, If you want to learn better, I encourage you to pause the video now and try to run the program by yourself, check the result and guess the meaning of the program. (5 seconds)

Before I explain the program (pause 3 secs)

you need to really understand what the statement a=a+1 means in programming .As I said in my previous video, for those who haven't learnt programming, they tend to think that this equal sign means an equation in mathematics and then try to simplify it like seconds) and come out this absurd result....(2 I want to emphasize here again that in programming, this equal sign doesn't mean an equation, but means an action of storing the result of the right hand side of the equal sign to the variable on the left hand side.

Lets see one example. Here variable A initially stored 3. And when we run the second statement a=a+1, the computer will first evaluate the result on the right hand side of the equal sign, it found that a should be 3, and the whole expression should be 3+1 which is (3 seconds) and then it stores this 4 back into variable a. Therefore, a=a+1 means to first calculate the result of a+1 and then store the result back to a.

Now, coming back to the topic of today. Since this kind of statement a equal to a plus something, which I call it x, always happens in programming, we have a simplified way to write it out. Here you can see we can write it as a += x.
Other operators we have learnt before can also be used in this kind of statement, as you can see seconds)

Therefore, this is the answer of today. Here you can see A initially stored and this statement will store the result of A + 3 and back to A, therefore, the result in a is her I won't explain this line by line as I think you can figure it out by (5 seconds)

Before we come to the end, I want you to think about the result of this program. You can pause the video now to think about it.... (10 seconds)

The answer is like this line a+=(b+3) can be written as a=a+(b+3).
the first two statements will store 1 and 2 into a and b
for this equal sign...(pause 2 seconds), the computer will find the result of the right hand side
here b+3 is but be careful.... we haven't instructed the computer to change the value of variable b here, we only want the computer to find the result of b+3 we only read the value of a and b here and do the calculation, and since a is 1, the result of the whole expression is
finally, the result will be written into variable a, so the value in A is now update to 6.
Therefore the result of the last two statements are 6 and

Thanks for watching and see you in the next video!

ertxxx
welcome to shbcf.ru