Edexcel IGCSE Computer Science 4CP0
Algorithms
Searching and Sorting Algorithms
Decomposition and Abstraction
Developing and Testing Code
Programming Constructs and Operators
Data Types and Data Structures
Input, Output and Validation
Data Representation
Data Storage and Compression
Encryption
Hardware and the CPU
Software
Programming Languages and Translators
Networks
Network Security
The Internet and the World Wide Web
Emerging Trends, Issues and Impact
Programming Constructs and Operators
Selection
- 3 things to know
- Papers 1 and 2
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.
Write Python code that prints Adult for an age of 18 or more and Child otherwise
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
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
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
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
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
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
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.
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.