Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

This topic introduces students to the concept of variables as placeholders for information in the code. They learn how to create, name, assign data to and refer to the contents of variables.

Learning objectives and goals

Be able to read, comprehend, trace, adapt and create Python code that:

Slide deck

The slide deck for this topic is on Google Slides, shared with the Output and Input chapters. A PDF copy is kept on Dodona too.

Teacher notes

Activities

Each skill has 3 to 4 individual projects associated with it that take students through the PRIMM pedagogical framework. They are numbered to try and make the order obvious. You can assign these one at a time or drip feed as students get to them.

Prior learning

Algorithms - sequences of instructions for a task.

Output - the information presented to the user by the computer. In our programs output will be in the form of text on screen.

Strings - data in text format.

Syntax - the format that code is written in. If code is not written in the correct format it creates a syntax error and the program will not run.

New learning

Variable - a placeholder for information that can change as the program runs.

Variable assignment - using the = symbol to store data in a variable.

Concatenation - joining the contents of variables to other variables and/or strings in output.

There are lots of similar tasks available online that you can use to supplement the ones in these resources. I can particularly recommend:

Students learn how to use variables to store data and refer back to it. Variables are used in a very similar way to letters in algebra: they represent the text. Students can call variables anything they like, but there are some good practice principles, and those are the ones collected under Errors and misconceptions to watch out for below.

Code examples

Assign data to a variable:

variable_name = "string data"
variable_name2 = 12

Concatenate a variable into an output. The str() is needed to convert the number in the variable into a string, so that it will work with the concatenation:

"Your name is " + name_variable
"You picked number " + str(number_variable)

Errors and misconceptions to watch out for