levo

Problem Solving with Programming

Selection and loops in Python

  • 3 things to know
  • Paper 2

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

See a huge jump in your memorisation

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Computational Thinking
Data
Computers
Networks

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

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.

AA normal test value is 14.
BA boundary test value is 16.
CAn erroneous test value is 20.

Build It trains answer structure

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

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 traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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