levo

Problem Solving with Programming

Selection and loops in Python

  • 3 things to know
  • Paper 2
Start revising · £5/month

Overview

if, elif and else, range() with worked values, for and while loops, iteration over lists and strings, nested loops, and single entry and exit points.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is the difference between initialisation and assignment?

Process

Define a command sequence.

Key term

What is printed when x = 7 runs through if x > 10: print("big"), then elif x > 5: print("medium"), then else: print("small")?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is the difference between initialisation and assignment?

    Model answer

    Initialisation gives a variable its first value, such as total = 0. Assignment is any statement that stores a value in a variable, including every later change.

  2. 2

    Define a command sequence.

    Model answer

    A command sequence is a group of statements carried out one after another in order. Statements at the same indentation inside a block form a sequence.

  3. 3

    What is printed when x = 7 runs through if x > 10: print("big"), then elif x > 5: print("medium"), then else: print("small")?

    Model answer

    The code prints medium. The first test is False, so the elif test x > 5 is checked and is True.

  4. 4

    Why is if mark >= 40: grade = "C", followed by elif mark >= 70: grade = "A", a logic error?

    Model answer

    Python stops at the first True test, so a mark of 85 is given C. The highest boundary must be tested first.

  5. 5

    List the values produced by range(5).

    Model answer

    The call range(5) produces 0, 1, 2, 3 and 4. The start defaults to 0 and the stop value 5 is not included.

  6. 6

    List the values produced by range(2, 11, 3).

    Model answer

    The values are 2, 5 and 8. The next value would be 11, which is the stop value and is excluded.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Computational Thinking
Data
Computers
Networks

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

The check is 45 + 27 = 72.
denarybinaryhexadecimal

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

A kibibyte (KiB) is 1,024 bytes. The figure 1,024 is 2¹⁰.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Problem Solving with Programming, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.