Drop links or images here to add them to the editor.

This topic adds the input command to the prior learning about output and variable assignment.

Learning objectives and goals

Students will learn to interpret, trace, identify and create Python code that uses:

Concept Explanation Python code Examples
Strings The text data type. All string data is treated as text, even if it is numerical characters. "string goes here" "This is a string"
Variable assignment Putting data into a variable. = num1 = 10
name = "Andy"
Concatenation Joining string literals (text in speech marks that outputs exactly as it appears in the code) to the contents of variables in output, or joining the contents of variables together. There are several ways of doing this, but I have used the plus symbol in my exercises. + print("Hello " + name)
full_name = first_name + last_name
Input Collecting data for processing. In these examples we collect input that the user types on the keyboard, but computers collect input in lots of ways: as sound, as mouse movements, with sensors. Input must ALWAYS be assigned to a variable or it will not be stored. All input is treated as strings. Any input that needs to be treated as a number must be cast into the new format. variable_name = input() print("What's your name?")
name = input()
print("Guess the secret number")
guess = int(input())

Slide deck

The slide deck for this topic is on Google Slides, shared with the Output and Variable assignment 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.

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.

New learning

Input - the data collected by the computer. In our programs input will be in the form of the user typing in. Input must be assigned to a variable or it will be discarded by the program.

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

Errors and misconceptions to watch out for

The first of those looks like this:

print("What's your name?")
name = input("Andy")