levo

Programming Constructs and Operators

Selection

  • 3 things to know
  • Papers 1 and 2
Start revising · £5/month

Overview

IF, ELSE and nested IF statements and Python if, elif and else chains, with worked outputs.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

How does an IF ... ELSE statement work?

Key term

Write Python code that prints Adult for an age of 18 or more and Child otherwise

Key term

Write Python code that gives grade A for 70 or more, B for 50 to 69 and U below 50

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    How does an IF statement work?

    Model answer

    An IF statement tests a condition. The commands inside run only if the condition is true.

  2. 2

    How does an IF ... ELSE statement work?

    Model answer

    The first block of commands runs if the condition is true. The ELSE block runs if the condition is false.

  3. 3

    Write Python code that prints Adult for an age of 18 or more and Child otherwise.

    Model answer

    The code is if age >= 18: print('Adult') else: print('Child'), with each print indented under its line.

  4. 4

    How is a choice between more than two options made in Python?

    Model answer

    Python uses if, then one or more elif branches, then an optional else. The first branch whose condition is true runs.

  5. 5

    Write Python code that gives grade A for 70 or more, B for 50 to 69 and U below 50.

    Model answer

    The code is if mark >= 70: grade = 'A', elif mark >= 50: grade = 'B', else: grade = 'U'.

  6. 6

    What is the output of this code when x is 7: if x > 10: print('big') elif x > 5: print('medium') else: print('small')?

    Model answer

    The first condition is false and the second is true. The output is medium.

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.

Algorithms
Searching and Sorting Algorithms
Decomposition and Abstraction
Developing and Testing Code

Cram the night before, weakest topic first

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

Denary is a base system.
1028

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.

Nibble means a group of four bits.
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 Programming Constructs and Operators, 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.