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

In a predict and run task you do not write code from scratch. You start from a small piece of working code, work out what you think it will do before you run it, and then run it to check whether you were right.

This task contains three examples. Work through them in order, because each one builds on the one before it.

Predict

For every example, study the code carefully and write down a prediction of what it will do when it runs. Your prediction should use the key terms variable, assign and concatenate. You can type your prediction straight into the code as a comment, on a line starting with #.

Only once you have written your prediction should you run the code and compare the result with what you expected.

Need more help with assignment? Click here. Need more help with concatenation? Click here.

Example 1

first_name = "Andy"
print(first_name)

Predict what this outputs, then run it. Which of the two lines stores something, and which one shows something?

Example 2

The first two lines are the ones you already met in example 1, repeated here so that this block runs on its own. The new work happens on the third line.

first_name = "Andy"
last_name = "Colley"
full_name = first_name + " " + last_name

print(full_name)

Predict what this outputs, then run it. Pay close attention to the " " in the middle of the concatenation, and to the fact that full_name is assigned the result of an expression rather than a value you typed out yourself.

Example 3

The same variables again, but this time they are concatenated into a longer sentence.

first_name = "Andy"
last_name = "Colley"
full_name = first_name + " " + last_name

print("Hello " + first_name + ". Your full name is " + full_name + ".")

Predict what this outputs, then run it. Count the pieces that are being concatenated, and work out exactly where each space and each full stop in the output comes from.

Help! My code doesn't work!

Make sure that you check for the following things:

  • You have typed the variable name exactly the same, capital letters included, every time.
  • There is a variable on the left of each assignment, and the data is on the right.
  • You have used a single = for assignment.
  • You have used the + symbol to concatenate (join).
  • The string text is surrounded by speech marks.
  • The + symbols and the variable names are not surrounded by speech marks.