Book 4 · Chapter P4.0
The practical exam and your evidence document
B4·0This chapter is in the ebook.
Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.
About this chapter
This chapter is about how the paper works rather than one syllabus section. Its companion material arrives with the chapter.
Paper 4 at a glance
Short code B4·0·10
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
The evidence document
Short code B4·0·11
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Reading a Paper 4 task
Short code B4·0·12
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Building the program in parts
Short code B4·0·13
# Steps : ARRAY[0:6] OF INTEGER, global
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
def DaysOver(Target):
Count = 0
for Day in range(7):
if Steps[Day] >= Target:
Count = Count + 1
return Count
def ShowWeek():
for Day in range(7):
print("Day " + str(Day + 1) + ": " + str(Steps[Day]))
# main program
ShowWeek()
print("Enter the daily target")
Target = int(input())
while Target < 1000 or Target > 20000:
print("Must be from 1000 to 20000")
print("Enter the daily target")
Target = int(input())
print("Days on target: " + str(DaysOver(Target)))Output
Day 1: 4200 Day 2: 8000 Day 3: 7650 Day 4: 12000 Day 5: 3900 Day 6: 8000 Day 7: 10500 Enter the daily target Must be from 1000 to 20000 Enter the daily target Days on target: 4
Steps = 7650
if Steps = 8000:
print("On target")= copied from the pseudocode into a Python condition: the program does not run at all.Output
ERROR (exit 1): if Steps = 8000: ^^^^^^^^^^^^ SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
How program code is marked
Short code B4·0·14
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
def DaysUnder(Target):
Count = 0
for Day in range(7):
if Steps[Day] < Target:
Count = Count + 1
return Count
print(DaysUnder(8000))
print(DaysUnder(4200))DaysUnder() counts the days below the target, so 8000 itself is not counted.Output
3 1
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
def BestDay():
Best = 0
for Day in range(1, 7):
if Steps[Day] > Steps[Best]:
Best = Day
return Best + 1
print(BestDay())
Steps[6] = 12000
print(BestDay())
Steps[0] = 15000
print(BestDay())BestDay() with the given data, then with a tie for the most steps, then with a new best on day 1.Output
4 4 1
Outputs that match exactly
Short code B4·0·15
Day = 3
Steps = 7650
print("Day", Day, ":", Steps)
print("Day " + str(Day) + ": " + str(Steps))print() put a space between items, so the first line is not the format the task asked for.Output
Day 3 : 7650 Day 3: 7650
Testing and screenshot evidence
Short code B4·0·16
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
def DaysOver(Target):
Count = 0
for Day in range(7):
if Steps[Day] >= Target:
Count = Count + 1
return Count
for Target in [5000, 8000, 8001, 1000, 20000]:
print(str(Target) + " -> " + str(DaysOver(Target)))DaysOver() (Python; the VB.NET and Java versions are online): 8000 and 8001 sit either side of a value in the array, and 1000 and 20000 are the ends of the accepted range.Output
5000 -> 5 8000 -> 4 8001 -> 2 1000 -> 7 20000 -> 0
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
def DaysOver(Target):
Count = 0
for Day in range(7):
if Steps[Day] >= Target:
Count = Count + 1
return Count
for Target in [5000, 8000, 8001, 1000, 20000]:
print(str(Target) + " -> " + str(DaysOver(Target)))DaysOver() test calls in all three languages.Output
5000 -> 5 8000 -> 4 8001 -> 2 1000 -> 7 20000 -> 0
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
def DaysUnder(Target):
Count = 0
for Day in range(7):
if Steps[Day] < Target:
Count = Count + 1
return Count
print("Enter the limit")
Limit = int(input())
while Limit < 500 or Limit > 15000:
print("Must be from 500 to 15000")
print("Enter the limit")
Limit = int(input())
print("Days under: " + str(DaysUnder(Limit)))Output
Enter the limit Must be from 500 to 15000 Enter the limit Days under: 3
Steps = [4200, 8000, 7650, 12000, 3900, 8000, 10500]
print("Enter a day number")
DayNumber = int(input())
while DayNumber < 1 or DayNumber > 7:
print("Enter a day number")
DayNumber = int(input())
print("Day " + str(DayNumber) + ": " + str(Steps[DayNumber - 1]))Output
Enter a day number Enter a day number Enter a day number Day 4: 12000
Planning your time
Short code B4·0·17
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
The language passport I: data and expressions
Short code B4·0·18
MaxSeats = 40 # CONSTANT: never assigned again
Booked = 27 # INTEGER
Rate = 2.5 # REAL
Name = "Zainab" # STRING
Free = MaxSeats - Booked
print("Free seats: " + str(Free))
print(str(Booked // 5) + " rows and " + str(Booked % 5) + " over")
print(Booked / 2)
print(Booked * Rate)
print(len(Name))
print(Name[0:3]) # MID(Name, 1, 3)
print(Name[-2:]) # RIGHT(Name, 2)
print(Name.upper())Output
Free seats: 13 5 rows and 2 over 13.5 67.5 6 Zai ab ZAINAB
The language passport II: selection and loops
Short code B4·0·19
Mark = 64
if Mark >= 70:
print("Distinction")
elif Mark >= 50:
print("Pass")
else:
print("Not yet")
for Count in range(1, 10, 4): # FOR Count <- 1 TO 9 STEP 4
print(Count)
Total = 0
Number = 1
while Total + Number <= 10: # WHILE: tested before each pass
Total = Total + Number
Number = Number + 1
print("Total " + str(Total))
Tries = 0
while True: # REPEAT ... UNTIL Tries * Tries > 20
Tries = Tries + 1
if Tries * Tries > 20:
break
print("Tries " + str(Tries))Output
Pass 1 5 9 Total 10 Tries 5
The language passport III: arrays, modules and input
Short code B4·0·20
Names = [""] * 5 # ARRAY[0:4] OF STRING
Names[0] = "Ali"
Grid = [[0] * 4 for Row in range(3)] # ARRAY[0:2, 0:3] OF INTEGER
Grid[2][3] = 9
def Larger(A, B): # FUNCTION ... RETURNS INTEGER
if A > B:
return A
return B
def ShowRow(Row): # PROCEDURE
Line = str(Grid[Row][0])
for Col in range(1, 4):
Line = Line + " " + str(Grid[Row][Col])
print(Line)
print(str(len(Names)) + " " + Names[0])
ShowRow(2)
print(Larger(12, 30))Output
5 Ali 0 0 0 9 30
print("Name?")
Name = input()
print("Age?")
Age = int(input())
print("Hours?")
Hours = float(input())
print(Name + " is " + str(Age + 1) + " next year")
print(Hours * 3)Output
Name? Age? Hours? Bilal is 18 next year 7.5
The Misconception Museum: slips in each language
Short code B4·0·21
Total = 0
for Day in range(4):
Total = Total + Day * 10
print("Total: " + str(Total))print runs four times, so the program outputs a running total, not the total.Output
Total: 0 Total: 10 Total: 30 Total: 60
Total = 0
for Day in range(4):
Total = Total + Day * 10
print("Total: " + str(Total))for line, Python refuses to run the program.Output
ERROR (exit 1): Total = Total + Day * 10 ^^^^^ IndentationError: expected an indented block after 'for' statement on line 2
Module Program
Sub Main()
Dim Scores(4) As Integer
Console.WriteLine(Scores.Length)
Try
Scores(5) = 80
Catch Problem As IndexOutOfRangeException
Console.WriteLine(Problem.Message)
End Try
End Sub
End ModuleDim Scores(4) makes five elements, 0 to 4. Writing to Scores(5) stops the program with the message caught here.Output
5 Index was outside the bounds of the array.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner In = new Scanner(System.in);
System.out.println("Continue? (Yes/No)");
String Answer = In.nextLine();
if (Answer == "Yes") {
System.out.println("== says they are equal");
} else {
System.out.println("== says they are different");
}
if (Answer.equals("Yes")) {
System.out.println("equals() says they are equal");
}
}
}== asks whether two strings are the same object, not whether they hold the same characters. Input: Yes.Output
Continue? (Yes/No) == says they are different equals() says they are equal
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(-7 // 2)/ always gives a real result; // divides and rounds down, even for a negative number.Output
3.5 3 1 -4
Module Program
Sub Main()
Dim Half As Integer
Console.WriteLine(7 / 2)
Console.WriteLine(7 \ 2)
Console.WriteLine(7 Mod 2)
Half = 7 / 2
Console.WriteLine(Half)
Half = 5 / 2
Console.WriteLine(Half)
End Sub
End Module/ gives a real result, and storing it in an Integer rounds it (3.5 to 4, but 2.5 to 2). \ divides and drops the fraction.Output
3.5 3 1 4 2
public class Main {
public static void main(String[] args) {
System.out.println(7 / 2);
System.out.println(7.0 / 2);
System.out.println(7 % 2);
System.out.println(-7 / 2);
}
}/ between two integers drops the fraction; one real operand makes it real division.Output
3 3.5 1 -3
print("First number?")
A = input()
print("Second number?")
B = input()
print(A + B)
print(int(A) + int(B))input() always returns a string: + joins the two strings until they are converted. Inputs: 5 and 3.Output
First number? Second number? 53 8
Command-word coach
Short code B4·0·22
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Past-paper practice
Short code B4·0·90
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Workbook 4: The practical exam and your evidence document
Short code W4·0 · Practical Programming Task Book
The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.
Starter files
Short code W4·0·K
Data files and skeleton code in Python, VB.NET, Java for this chapter's tasks arrive here with the chapter.


