All subjects · Computer Science · WCP02 Practical Programming and Problem-solving

Sequence, input and output in Python

Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving

Unit 2 is a three-hour practical exam in Python 3. Every program starts with the simplest control flow construct: sequence, with input and output.

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

Sequence (spec 7.1.1)

Sequence means instructions run one after another, top to bottom. Changing the order of two lines can change the result, so order matters.

price = 4
price = price * 3
print(price)
price = price + 2
print(price)

Output:

12
14

Output with print()

print() displays values and moves to a new line. Several items separated by commas are printed with a single space between them. The optional sep= and end= arguments change the separator and the line ending. (sep= and end= are standard Python but are not listed in the PLS; valid code outside the PLS still earns marks.)

print("Total:", 5 + 3)
print("a", "b", "c", sep="-")
print("no new line", end=" ")
print("here")

Output:

Total: 8
a-b-c
no new line here

Input with input()

input(prompt) displays the prompt, waits for the user and always returns a string. Convert it before doing arithmetic:

age = int(input("Enter your age: "))
print("Next year you will be", age + 1)

If the user types 16, the output is: Next year you will be 17. Without int(), age + 1 would raise a TypeError, because you cannot add a str and an int.

Comments

A comment starts with # and runs to the end of the line. Python ignores it. In the exam, informative comments earn clean code marks, and the first comment of a program can describe what the whole program does.

Worked example

A program should ask for a length and a width in metres and display the area. Write it in sequence.

  1. Get the inputs and convert them: length = float(input("Length: ")) and width = float(input("Width: "))
  2. Process: area = length * width
  3. Output: print("Area:", area)
  4. Test it: inputs 2.5 and 4 give: Area: 10.0

Answer: Input, then process, then output, in that order.

Key idea: Sequence runs top to bottom; print() separates items with a space by default; input() always returns a string, so convert it with int() or float().

Check yourself

  1. What is displayed when this code runs? ```python x = 10 y = x x = 4 print(y) ```
    Show answer

    10. y was given the value of x (10) before x changed, so 10 is displayed.

  2. What is displayed when this code runs? ```python print("2026", "11", "08", sep="/") ```
    • 2026/11/08
    • 2026 11 08
    • 20261108
    • 2026/11/08/
    Show answer

    2026/11/08. sep= replaces the default single space between items, giving 2026/11/08.

  3. What is displayed when this code runs? ```python print("Hi", end="") print("there") ```
    • Hi there
    • Hi / there
    • Hithere
    • there / Hi
    Show answer

    Hithere. end="" stops print() moving to a new line, so the second print continues on the same line: Hithere.

  4. The user types 7 when prompted. What is the complete line displayed? ```python n = input("Number: ") print(n * 2) ```
    Show answer

    Number: 77. input() returns the string "7", and a string times 2 repeats it, so after the prompt the complete line is Number: 77.

  5. The user types 7 when prompted. What is the complete line displayed? ```python n = int(input("Number: ")) print(n * 2) ```
    Show answer

    Number: 14. This time the input is converted to an int first, so 7 * 2 = 14 and the line is Number: 14.

  6. Which exception is raised when this code runs? ```python age = "16" print(age + 1) ```
    • ValueError
    • TypeError
    • NameError
    • SyntaxError
    Show answer

    TypeError. Adding a str to an int is a TypeError: the operation is not defined for those types.

  7. A program must display a total, but the line print(total) comes before total = a + b. What happens when it runs?
    • It displays 0
    • Python moves the print after the calculation
    • It displays nothing
    • A NameError, because total does not exist yet
    Show answer

    A NameError, because total does not exist yet. Code runs in sequence. When print(total) runs, total has not been created, so Python raises NameError.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.