04 — Update: change a value
Games need scores that change. set score to 0 starts a score, and add
changes it without + or =.
Steps
Create
score.nme:
run it →set score to 0 score add 1 show scoreset score to 0stores the number 0;score add 1increases it. The program prints1.The value can be changed in several natural word orders:
run it →add 1 to score score increase by 1 subtract 1 from scoreAdd these lines one at a time and watch
show scorechange.Korean works the same way:
run it →점수는 0 점수에 1 더해 점수 보여줘 점수에서 1 빼줘Multiplying and dividing work the same way:
run it →multiply score by 2 divide score by 2 점수에 2 곱해 점수를 2로 나눠The advanced spelling
+=means the same thing and is valid Python:score += 1
Try it yourself
Count up to 5 by adding, then count back down by subtracting:
set score to 0
score add 5
score subtract 2
show score
run it →What you learned
set score to 0stores a number;점수는 0is the Korean form.score add 1,add 1 to score, andscore increase by 1all add.subtract 1 from score/점수에서 1 빼줘subtract, andmultiply score by 2/점수에 2 곱해multiplies.score += 1is the same idea in ordinary Python.