Year 8 › Python I › Lesson 2 of 5
Year 8 · Spring 2 · Python I Variables, data types and arithmetic
Topic 13 Programming basics
KS3 Computing · A program stores information in variables, works on it with operators, and controls the order with sequence, selection and iteration. Examples are in Python, with Scratch alongside for Year 7.
Programming Cambridge Lower Secondary Computing 0860
You will learn to Explain what a variable is, and read = as 'becomes'. Identify int, float and str values, like 7, 3.5 and "7". Use int() to turn typed input into a number before doing maths. Use // and % to work out DIV and MOD, like 17 // 5 = 3 and 17 % 5 = 2.
Success criteria I can read score = score + 10 aloud as 'score becomes score plus 10'. I can explain why "7" + "7" gives "77", but 7 + 7 gives 14. I can build a tiny calculator that adds two numbers the user types.
variable A named place in memory that holds a value.
assignment Storing a value in a variable. = in Python, ← in pseudocode.
concatenation Joining strings together: "7" + "7" = "77".
Casting Changing a value from one data type to another, like int("13").
Selection Choosing a path with if / else.
Iteration Repeating steps: a loop.
Boolean A value that is only True or False.
Infinite loop A loop whose condition never becomes false.
Variables: labelled boxes A variable is a named box in memory that holds a value.
score = 0
score = score + 10
print(score) score = 0: make a box called score, put 0 in it. This is assignment .score = score + 10: read the right side first. 0 + 10 = 10. Put 10 back in the box.print(score) shows 10 .! Watch outIn code, = means 'store', not 'equals'. To ask if two things are equal, use ==.
e.g. ExampleScratch: the orange 'set score to 0' and 'change score by 10' blocks.
Data types ! Watch out"7" in quotes is text. 7 + 7 gives 14, but "7" + "7" gives 77 (joining text, called concatenation ).
Arithmetic operators e.g. Examplen % 2 == 0 checks if a number is even.
The steps for this lesson
Mark this lesson as done Saved on this device.
← Previous lesson print, input and sequence Next lesson → if / elif / else