Pearson Edexcel 1CP2 GCSE Computer Science · Topic 6: Problem Solving with Programming

Stretch tasks Programming Fundamentals in Python

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

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

Task 3

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

Task 4

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

  1. What does input() always return?

    • A Boolean
    • A string
    • An integer
    • A float
  2. What does this print?

    print(7 // 2)

  3. What does this print?

    print(7 % 2)

  4. What does this print?

    print(7 / 2)

  5. 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
  6. x = 5 asks whether x holds 5.

    • True
    • False
  7. 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
  8. 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"
  9. Which expression tests whether n is even?

    • n / 2 == 0
    • n % 2 == 1
    • n % 2 == 0
    • n // 2 == 0
  10. 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
  11. 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
  12. What is the data type of 68.4 in Python?

Quiz Challenge, round 2: Quick Fire

  1. 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")

  2. Explain the difference between = and == in Python. [2 marks]

  3. Explain how // and % could convert 135 seconds into minutes and seconds. [2 marks]

  4. Explain why the order of the conditions in an if, elif chain matters. [2 marks]

Quiz Challenge, round 3: Big Think

  1. 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]

  2. 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

  1. input() gives back 15 as a number or a string?

    • A string
    • A number
  2. Does range(1, 5) include 5?

    • Yes
    • No
  3. 7 // 2 or 7 % 2: which gives the remainder?

    • 7 // 2
    • 7 % 2
  4. Which one assigns: = or ==?

    • =
    • ==
  5. Number of repeats is known in advance: for or while?

    • while
    • for
  6. What type is True?

    • str
    • bool
  7. Does changing a line's indentation change what it belongs to?

    • No: it is just tidiness
    • Yes: indentation is the syntax
  8. Which is clearer for a message with several values?

    • An f-string
    • Many commas

Memory Match: match each term to its meaning

TermMeaning
A Variable1 A fixed value, written in capitals
B Constant2 A named value that can change
C Casting3 A string with values in braces
D Modulus4 Whole number part only
E Integer division5 The remainder after division
F f-string6 Converting a value's data type

Sort It: tick one box in each row

Which data type does each value have?

Statementintfloatstrbool
True
68.4
"Amira"
15
x == 5
7 // 2
input()
len("hello")
age >= 13
7 / 2
float("3")
"15"
Answers

Round 1: Quiz Blitz

  1. A string Even when the user types 15, it comes back as text.
  2. 3 // is integer division: the whole number part only.
  3. 1 % gives the remainder.
  4. 3.5 / always gives a float.
  5. 1, 2, 3, 4, 5 range stops before the second number.
  6. False One equals sign assigns. x == 5 compares.
  7. In capitals, such as VAT_RATE Python has no constant keyword, so capitals signal one.
  8. grade == "A" or grade == "B" Each side of or must be a complete comparison.
  9. n % 2 == 0 An even number leaves no remainder when divided by 2.
  10. Pass Only the first true condition runs, so the order of the tests matters.
  11. 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.
  12. 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 answer

    input() 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 answer

    A 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 answer

    135 // 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 answer

    Python 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 answer
    Python
    total = 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 answer

    First, 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

  1. A string input() always returns text, so it must be cast before arithmetic.
  2. No range stops before the second number.
  3. 7 % 2 // gives the whole number part. % gives the remainder.
  4. = = puts a value into a variable. == compares two values.
  5. for A for loop is count controlled. A while loop is condition controlled.
  6. bool True is a Boolean value. "True" in quotation marks would be a string.
  7. Yes: indentation is the syntax In Python, indentation decides which block a line is inside.
  8. 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

  1. bool True True and False are Booleans.
  2. float 68.4 A decimal point makes it a float.
  3. str "Amira" Text in quotation marks is a string.
  4. int 15 A whole number is an int.
  5. bool x == 5 == gives True or False.
  6. int 7 // 2 Integer division gives an int.
  7. str input() input() always returns a string.
  8. int len("hello") len returns a whole number.
  9. bool age >= 13 A comparison gives a Boolean.
  10. float 7 / 2 / always gives a float.
  11. float float("3") float() converts to a float.
  12. str "15" In quotation marks, even digits are a string.