GCSE Computer Science Paper 1 (Python) - June 2024 Study Guide
- Paper Title: GCSE Computer Science Paper 1 Computational thinking and programming skills – Python.
- Date: Wednesday 15 May 2024 (Afternoon).
- Time Allowed: 2 hours.
- Total Marks Available: 90.
- Identification Code: IB/G/Jun24/G4005/E11 8525/1B.
- Materials: No calculators permitted. Black ink or ball-point pen for text; pencil for drawing.
- Programming Constraints: Coded solutions must be written in Python. Indexing starts at 0 unless otherwise stated.
Question 1: Pseudo-code and Basic Programming Definitions
- Algorithm (Figure 1):
*
filmext←"Godzillavs.Kong"
* yearext←2021
* OUTPUText"Pleaseguessaletter"
* letterext←USERINPUT - Length Assignment: To assign the length of the string
film to a variable value, the correct pseudo-code is: valueext←LEN(film). - POSITION Subroutine Explanations:
*
POSITION("Godzillavs.Kong","o") returns 1.
* POSITION("Godzillavs.Kong","z") returns 3.
* To find the position of the input letter in film and store it in location: locationext←POSITION(film,letter). - Data Types: The most suitable data type for the variable
year (2021) is integer. - Assignment Statement Definition: A programming statement used to set or change the value stored in a variable.
- Python String Concatenation Task:
* A program that gets a film name and displays "You entered" followed by the film name on one line:
python
film_name = input("Enter a film: ")
print("You entered", film_name)
Question 2: Logical Operators and Modulus
- Algorithm Detail (Figure 2):
1.
numext←USERINPUT
2. IFextNOT(num>1)extORnum>20extTHEN
3. OUTPUText"False"
4. ELSEIFextnum>1extANDnum<15extTHEN
5. OUTPUText"Almost"
6. ELSEIFextnumMOD5=0extTHEN
7. OUTPUText"True"
8. ELSE
9. OUTPUText"Unknown"
10. ENDIF - Modulus Examples:
*
14extMOD3=2
* 24extMOD5=4 - Relational Operators: A relational operator (e.g.,
>) is first used on Line 2 of Figure 2. - Tracing User Input:
* If input is 5: Line 4 evaluated as
5>1extAND5<15, which is True. Output is Almost.
* To get True as output, the input must be 20.
* Logic: 20>20 is False. 20>1extAND20<15 is False. 20extMOD5=0 is True. - Logic Simplification: Line 2 rewritten without
NOT: IFextnumext≤1extORnum>20extTHEN. - Unknown Output Value: An input of 16, 17, 18, or 19 would result in "Unknown".
Question 3: Random Numbers and Validation
- Python Guessing Game (Figure 3):
*
import random is used.
* Line 2 task: Generate a random integer between 1 and 100 inclusive using random.randrange(a, b).
* Correct code: randomNumber=random.randrange(1,101). - Validation Logic: Line 5 in the program checks
while userNumber < 1 or userNumber > 100:. - Test Plan (Table 1):
* Erroneous Data: 150 (outside range).
* Boundary Data: 1, 100 (edge of acceptable range).
* Normal Data: Any integer from 2 to 99.
- Error Categorization:
* Syntax Error: Typed
whil instead of while.
* Logic Error: Typed userNumber >= 100 instead of userNumber > 100 (this would incorrectly reject the valid number 100).
Question 4: Problem-Solving Concepts
- Abstraction: The process of removing unnecessary details from a problem to focus on the essential characteristics.
- Decomposition: The process of breaking a complex problem down into smaller, more manageable sub-problems.
Question 5: Wedding Hire Algorithm Trace
- Pricing Logic (Figure 4):
* If guests
>50: totalCost=Guestsimes2
* Else if guests ≥25: totalCost=Guestsimes4
* Else: totalCost=Guestsimes5
* Rooms add Roomsimes100. If totalCost<1400, add charge (25). - Trace Scenarios:
* Scenario A: 50 Guests, 5 Rooms.
guests≥25 condition met. 50imes4=200. 200+(5imes100)=700. 700<1400 is true. 700+25=725.
* Scenario B: 30 Guests, 5 Rooms. 30imes4=120. 120+500=620. 620+25=645.
* Scenario C: 20 Guests, 10 Rooms. 20imes5=100. 100+1000=1100. 1100+25=1125.
Question 6: Essay Mark Python Program
- Problem: Calculate total mark for
e1, e2, e3 with late penalties. - Penalties:
* 1 essay late:
−10 marks.
* >1 essay late: total mark halved.
* Final mark cannot be below 0. - Solution Structure:
python
late_count = int(input("Enter number of late essays: "))
total_mark = e1 + e2 + e3
if late_count == 1:
total_mark = total_mark - 10
elif late_count > 1:
total_mark = total_mark // 2
if total_mark < 0:
total_mark = 0
print(total_mark)
Question 7: Sweet Stock Codes
- Code Structure:
sweetID + sweetName[0] + sweetName[1] + brand[0]. - Examples:
* WINE GUMS (S1, MAYNARDS) → S1WIM
* STARBURST (S3, WRIGLEY) → S3STW
- Python Implementation:
python
sid = input()
sname = input()
brand = input()
code = sid + sname[0] + sname[1] + brand[0]
Question 8: Array/Trace Table for Sales Algorithm
- Algorithm (Figure 6):
* Lists:
days = [10, 15, 4], sales = [20, 33, 12], weeks = [0, 0, 0].
* Process: daysTotal=days[i]+sales[i], weeks[i]=daysTotalextDIV7. - Iteration Trace:
1.
i=0: 10+20=30. 30extDIV7=4. weeks = [4, 0, 0].
2. i=1: 15+33=48. 48extDIV7=6. weeks = [4, 6, 0].
3. i=2: 4+12=16. 16extDIV7=2. weeks = [4, 6, 2].
* Final Output: 4+6+2=12.
Question 9: Records and Data Structures
- Data Structure Definition: An organized collection of values.
- Record Structure (Figure 7):
pseudo
RECORD Book
bookName : String
author : String
price : Real
ENDRECORD
B1 ← Book("The Book Thief", "M Zusak", 9.99)
B2 ← Book("Divergent", "V Roth", 6.55)
- Pseudo-code Comparison Logic:
pseudo
IF B1.price > B2.price THEN
OUTPUT B1.bookName
ELSEIF B2.price > B1.price THEN
OUTPUT B2.bookName
ELSE
OUTPUT "Neither"
ENDIF
Question 10: Subroutine Execution and Parameters
- Code Trace Figure 8:
-
First(p1,p2,p3) prints Second(p2+p3,p1).
- Second(p1,p2) returns v1=p1+p2. If v1>12, add Third(p1).
- Third(p1) returns 2 if p1>3, else 0. - Call 1:
First(3,4,4)
- v1=4+4=8
- Second(8, 3)
ightarrow v1 = 11. 11ext≤12. Returns 11. - Call 2:
First(3,4,8)
- v1=4+8=12
- Second(12, 3)
ightarrow v1 = 15. 15>12, so v1=15+Third(12).
- Third(12) = 2
ightarrow 15 + 2 = 17.
Question 11: Authentication Python Task
- Task: User repeated input for username/password authentication.
- Valid Credentials:
Yusuf5 with 33kk, Mary80 with af5r. - Example Python Code:
python
authenticated = False
while authenticated == False:
u = input("Username: ")
p = input("Password: ")
if (u == "Yusuf5" and p == "33kk") or (u == "Mary80" and p == "af5r"):
print("Access granted")
authenticated = True
else:
print("Access denied")
Question 12: Sliding Puzzle Logic
- Mechanics: 3x3 board. Value 0 is blank. Tiles 1-8 move one position (up, down, left, right) into the blank space.
- Subroutines:
*
getTile(row, column): Returns tile number.
* move(row, column): Moves tile to blank space if adjacent.
* solved(): Returns Boolean.
* checkSpace(row, column): Returns True if blank space is adjacent. - Finding the Blank Space (Figure 16): Uses nested iteration (range 3) to check all nine grid positions for the value 0 and stores the coordinates in
ref1 and ref2. - Tile Comparison Task: Write Python to check if row 0 has tiles in increasing order (n, n+1, n+2).
python
t1 = getTile(0, 0)
t2 = getTile(0, 1)
t3 = getTile(0, 2)
if t2 == t1 + 1 and t3 == t2 + 1:
print("Yes")
else:
print("No")
- Game Helper Task: Write Python to prompt moves until
solved() is true.
python
while solved() == False:
r = int(input("Row: "))
c = int(input("Col: "))
if checkSpace(r, c) == True:
move(r, c)
else:
print("Invalid move")
Question 13 & 14: Search and Selection
- Linear Search Process: Commences at the start of the list and compares the target value with each element sequentially until the value is found or the end of the list is reached.
- Local Variables: They only exist and are accessible within the subroutine or block of code in which they are declared (local scope).
- Museum Subroutine (
countDays):python
def countDays(num_days):
over_200 = 0
for i in range(num_days):
visitors = int(input("Enter visitors: "))
if visitors > 200:
over_200 += 1
return over_200
Question 15: Cell Row Game Logic
- Game Parameters (Figure 21):
* Start at position 0.
* Inputs: 1 to advance 1 cell, 2 to advance 2 cells.
* Failure conditions: If position
>extendofrow or cell contains 'X', reset to position 0 and display "Bad move".
* Victory: Reach the last index exactly. - Python Extension Task:
python
pos = 0
lastPos = len(row) - 1
while pos < lastPos:
move = int(input("Move 1 or 2: "))
pos = pos + move
if pos > lastPos or row[pos] == "X":
print("Bad move")
pos = 0
# Game naturally finishes when pos == lastPos