Pearson Edexcel 1CP2 GCSE Computer Science · Topic 6: Problem Solving with Programming
Stretch tasks Programming Fundamentals in Python
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
This or That
Pixel the cat asks 8 questions. Each has two answers: pick the right one.
- Two answers to every question
- A fish treat for every right answer
- Streaks win Pixel shades, then a party hat
About 4 minutes
Memory Match
Flip the cards two at a time to match each term card to its meaning card.
- 12 cards: each term has a meaning
- One peek at every card
- Combo points for pairs found in a row
6 pairs, about 4 minutes
Sort It
Sort each statement into the right box, like the tick-box tables in the exam.
- 12 cards to sort into 4 boxes
- Drag a card, tap a box or press its number
- Combo points for cards sorted in a row
12 cards, about 4 minutes
The games need JavaScript. Every question is below, with the answers at the end.
Read the lesson: Programming Fundamentals in Python
Programming Fundamentals in Python: the questions
Quiz Challenge, round 1: Quiz Blitz
What does input() always return?
- A Boolean
- A string
- An integer
- A float
What does this print?
print(7 // 2)What does this print?
print(7 % 2)What does this print?
print(7 / 2)What does range(1, 6) give?
- 1, 2, 3, 4, 5, 6
- 0, 1, 2, 3, 4, 5
- 2, 3, 4, 5, 6
- 1, 2, 3, 4, 5
x = 5 asks whether x holds 5.
- True
- False
How are constants written, by convention, in Python?
- Starting with a number
- In capitals, such as VAT_RATE
- With a const keyword
- In quotation marks
Which condition correctly tests for grade A or B?
- grade = "A" or "B"
- grade == "A" or grade == "B"
- grade == "A" or "B"
- grade == "A" and "B"
Which expression tests whether n is even?
- n / 2 == 0
- n % 2 == 1
- n % 2 == 0
- n // 2 == 0
What is printed for a mark of 80?
mark = 80 if mark >= 40: print("Pass") elif mark >= 70: print("Distinction")- Distinction
- Pass, then Distinction
- Nothing
- Pass
Which TWO does a while loop need to work properly?
Tick 2.
- It uses range()
- It has an else
- It runs exactly ten times
- The condition's variable has a value before the loop
- Something inside the loop can change that variable
What is the data type of 68.4 in Python?
Quiz Challenge, round 2: Quick Fire
This program should print Adult for anyone aged 18 or over, but it fails. Explain why, and how to fix it. [2 marks]
age = input("How old are you? ") if age >= 18: print("Adult")Explain the difference between = and == in Python. [2 marks]
Explain how // and % could convert 135 seconds into minutes and seconds. [2 marks]
Explain why the order of the conditions in an if, elif chain matters. [2 marks]
Quiz Challenge, round 3: Big Think
Write a Python program that keeps asking the user for whole numbers until they enter 0. It should then output the sum of the numbers and the biggest one entered. [6 marks]
A student's program asks for a test mark and prints a grade, but every student gets a Pass, and typing a mark of 85 sometimes crashes it. Explain three likely causes and how to fix each one. [6 marks]
This or That: tick the right answer
input() gives back 15 as a number or a string?
- A string
- A number
Does range(1, 5) include 5?
- Yes
- No
7 // 2 or 7 % 2: which gives the remainder?
- 7 // 2
- 7 % 2
Which one assigns: = or ==?
- =
- ==
Number of repeats is known in advance: for or while?
- while
- for
What type is True?
- str
- bool
Does changing a line's indentation change what it belongs to?
- No: it is just tidiness
- Yes: indentation is the syntax
Which is clearer for a message with several values?
- An f-string
- Many commas
Memory Match: match each term to its meaning
| Term | Meaning |
|---|---|
| A Variable | 1 A fixed value, written in capitals |
| B Constant | 2 A named value that can change |
| C Casting | 3 A string with values in braces |
| D Modulus | 4 Whole number part only |
| E Integer division | 5 The remainder after division |
| F f-string | 6 Converting a value's data type |
Sort It: tick one box in each row
Which data type does each value have?
| Statement | int | float | str | bool |
|---|---|---|---|---|
True | ||||
68.4 | ||||
"Amira" | ||||
15 | ||||
x == 5 | ||||
7 // 2 | ||||
input() | ||||
len("hello") | ||||
age >= 13 | ||||
7 / 2 | ||||
float("3") | ||||
"15" |
Answers
Round 1: Quiz Blitz
- A string Even when the user types 15, it comes back as text.
- 3 // is integer division: the whole number part only.
- 1 % gives the remainder.
- 3.5 / always gives a float.
- 1, 2, 3, 4, 5 range stops before the second number.
- False One equals sign assigns. x == 5 compares.
- In capitals, such as VAT_RATE Python has no constant keyword, so capitals signal one.
- grade == "A" or grade == "B" Each side of or must be a complete comparison.
- n % 2 == 0 An even number leaves no remainder when divided by 2.
- Pass Only the first true condition runs, so the order of the tests matters.
- The condition's variable has a value before the loop; Something inside the loop can change that variable Miss either and the loop never starts or never ends.
- float A number with a decimal point is a float.
Round 2: Quick Fire
- input() returns a string, which is compared with a number
- Cast the input with int()
Model answerinput() always returns a string, so age holds text such as "18", and comparing text with the number 18 fails. Wrapping the input in int() casts it to an integer: age = int(input("How old are you? ")).
- = assigns a value to a variable
- == compares two values, giving True or False
Model answerA single = assigns a value to a variable, so x = 5 stores 5 in x. A double == compares two values and gives True or False, so x == 5 asks whether x holds 5.
- 135 // 60 gives 2 whole minutes
- 135 % 60 gives the remainder, 15 seconds
Model answer135 // 60 gives 2, the whole number of minutes. 135 % 60 gives the remainder, 15, so the answer is 2 minutes 15 seconds.
- Only the first true condition runs, and the rest are skipped
- An example, such as a mark of 80 getting Pass
Model answerPython tests the conditions from the top and runs only the first one that is true, skipping the rest. If mark >= 40 came before mark >= 70, a mark of 80 would get Pass instead of Distinction.
Round 3: Big Think
- A running total set to 0 before the loop
- The input is cast to an integer
- A while loop that stops at 0
- Each number is added to the total
- Each number is compared with the largest so far
- The largest starts from the first number
- The total is printed after the loop
- The largest is printed after the loop
Model answerPythontotal = 0 number = int(input("Enter a whole number, or 0 to stop: ")) largest = number while number != 0: total = total + number if number > largest: largest = number number = int(input("Enter a whole number, or 0 to stop: ")) print("Total:", total) print("Largest:", largest)- The conditions are in the wrong order, so a lower test comes first
- Put the highest condition first
- input() returns a string
- Cast it with int()
- A crash comes from text that cannot be converted, such as a typing slip
- Validate the entry before converting it
- Using = instead of == in a condition
- Indentation errors put lines in the wrong block
Model answerFirst, the conditions are probably in the wrong order: if mark >= 40 is tested before mark >= 70, every passing mark matches it first, so the highest condition must be tested first. Second, input() returns a string, so the mark must be cast with int() before it is compared with a number. Third, the crash happens when what is typed cannot be converted, such as 8S instead of 85, which makes int() raise a ValueError, so the entry should be validated with isdigit() before it is converted. A single = instead of == in a condition, or wrong indentation that puts a line in the wrong block, would also cause errors.
This or That
- A string input() always returns text, so it must be cast before arithmetic.
- No range stops before the second number.
- 7 % 2 // gives the whole number part. % gives the remainder.
- = = puts a value into a variable. == compares two values.
- for A for loop is count controlled. A while loop is condition controlled.
- bool True is a Boolean value. "True" in quotation marks would be a string.
- Yes: indentation is the syntax In Python, indentation decides which block a line is inside.
- An f-string f"You scored {score} out of {total}" reads like the finished sentence.
Memory Match
- A 2 Variable: A named value that can change
- B 1 Constant: A fixed value, written in capitals
- C 6 Casting: Converting a value's data type
- D 5 Modulus: The remainder after division
- E 4 Integer division: Whole number part only
- F 3 f-string: A string with values in braces
Sort It
- bool
TrueTrue and False are Booleans. - float
68.4A decimal point makes it a float. - str
"Amira"Text in quotation marks is a string. - int
15A whole number is an int. - bool
x == 5== gives True or False. - int
7 // 2Integer division gives an int. - str
input()input() always returns a string. - int
len("hello")len returns a whole number. - bool
age >= 13A comparison gives a Boolean. - float
7 / 2/ always gives a float. - float
float("3")float() converts to a float. - str
"15"In quotation marks, even digits are a string.