Edexcel GCSE Computer Science 1CP2
Computational Thinking
Data
Computers
Networks
Issues and Impact
Problem Solving with Programming
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.
Define a command sequence.
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
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
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
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
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
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
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.
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.