Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views17 pages

Computer Science Mock Marking Scheme

The document is a marking scheme for the Pre-Leaving Certificate Examination 2024 in Higher and Ordinary Level Computer Science. It includes various sections with short answer questions covering topics such as programming concepts, testing, algorithms, and ethical considerations in AI. Each question has specific marking criteria and sample answers to guide the evaluation process.

Uploaded by

northernsnowdog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views17 pages

Computer Science Mock Marking Scheme

The document is a marking scheme for the Pre-Leaving Certificate Examination 2024 in Higher and Ordinary Level Computer Science. It includes various sections with short answer questions covering topics such as programming concepts, testing, algorithms, and ethical considerations in AI. Each question has specific marking criteria and sample answers to guide the evaluation process.

Uploaded by

northernsnowdog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

*WMS34* Part of

CǞǠǝǘǙȨǛ SȰǤȨǟȰȨ
HIGHER & ORDINARY LEVEL
MARKING SCHEME
Pre-Leaving Certificate Examination 2024

Higher Level: page 2


Ordinary Level: page 18
HIGHER LEVEL Section A - Short Answer Questions

Section A 45 marks

Answer any nine questions. Each question carries 5 marks.

Question 1

Please study the code carefully and then answer the following question: Given the following six
lines of code from a program, for each line, fill in the value stored in the variable answer.

1 answer = 7
2 name = “Robin”
3 answer += 1
4 name = answer
5 answer = “Charlie”
6 answer = name

Lines of Python code Value stored in “answer” at each line

answer = 7 7

name =”Robin” 7

answer += 1 8

name = answer 8

answer = “Charlie” “Charlie”

answer = name 8

*(Note) – 5 marks, best 5 count. 0 if incorrect.

Question 2

Briefly describe one problem that can be solved using heuristics and why it needed a heuristic
approach to be solved.

Sample Answer, not required, red components are the marking scheme.

Consider yourself a salesperson that must visit multiple places before returning home. You must
determine the fastest path in order to save time and money. The “Travelling Salesman Problem” (TSP)
is an example of this problem and it is heuristic. Because there are so many potential routes to take
when there are several cities to visit, it is necessary to use a heuristic technique because doing so
would take a long time.

Heuristic methods are intelligent ways that quickly identify a reasonably short route, even if it isn’t
really the shortest route possible. When there are numerous cities to visit, these techniques are
crucial for effectively resolving TSP and difficulties of a similar nature. Sat navigation could have also
been used.

3 marks for why (Fair description - limited understanding = 1 mark)


2 marks for reasonable example (Fair description - limited understanding = 1 mark)

PAGE 2 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section A (continued) HIGHER LEVEL

Question 3

The following code was intended to replace any negative numbers in a list with the value 0.

1 myList = [1, 2, 3, 4, -5, 6]


2
3 for item in myList:
4 if item < 0:
5 item = 0
6
7 print (myList)

However, the above code does not work as intended, printing out the result: [1, 2, 3, 4, -5, 6]

Explain why the code did not work as intended.

The reason for this issue/bug is that item is a variable assigned for the loop iterations (for loop).
Each list item is copied into this variable (item), and when a <0 value is identified it is then modified.
However, the variable item is modified and not the actual list. When you then print the list the same
values are presented.

2 marks for mentioning the variable item (Fair description - limited understanding = 1 mark)
3 marks for why this occurred, as in the variable was assigned the change, and not the
element in the list (Fair description - limited understanding = 1 mark)

Question 4

Testing is used in software development. The below code was intended to replace any negative
numbers in a list with the value 0, but instead it outputs [1, 2, 3, 4, -5, 6], not changing the
negative values as intended.

1 myList = [1, 2, 3, 4, -5, 6]


2
3 for item in myList:
4 if item < 0:
5 item = 0
6
7 print (myList)

Explain how you might test the above code to identify the errors in the program.

Mention an appropriate test, for example, use case or even a unit test (you can ignore if they leave
out it should be a function). 2 marks

Explanation of the test process selected


3 marks (Fair description - limited understanding = 1 mark)

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 3 OF 31


HIGHER LEVEL Section A (continued)

Question 5

Describe what a unit test is, and how it differs from a system test.

Individual components or modules of a software program are verified separately during a unit test. A
unit test’s objective is to verify that each module or component of the software performs as intended.
The smallest tested component of the code, such as a function, is referred to as a “unit” in this
context. These are more often than not automated.
3 marks must include small unit and automated
(Fair description - limited understanding = 1 mark)

System tests, on the other hand, evaluate the behaviour of the entire software system as a whole.
These tests verify that all the components of the system work together correctly to deliver the
expected functionality.
2 marks must include user and overall system
(Fair description - limited understanding = 1 mark)

Question 6

The list below contains 100,000 integers. Only the first six items in the list are shown.

myList = [1, 2, 3, 4, -5, 6, ...]

(a) Why would you not present the data in the above form to someone that wants to find the
number of items in the list that are negative?

Data in the above format as above is not readable by humans, for example, if you were to see how
many negative numbers in the 100,000 in a file you would not be able to, it would be too hard for
humans to read.

3 marks must include size and non interpretability


(Fair description - limited understanding = 1 mark)

(b) Name one graphical form that would be suitable for presenting the data in the list, and
one graphical form that would be unsuitable and why (for each form).

A bar graph would be suitable (or pie chart).


A line graph could be unsuitable

2 marks one for each (Fair description - limited understanding = 1 mark)

PAGE 4 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section A (continued) HIGHER LEVEL

Question 7

Below is the code of a sorting algorithm:

myList = [9, 10, 30, 19, 3]

for index in range(1, len(myList)):


itemToInsert = myList[index]
position = index
while position > 0 and myList[position-1] > itemToInsert:
myList[position] = myList[position-1]
myList[position-1] = itemToInsert
position -= 1

(a) Name the sorting algorithm.

Insertion sort

3 marks (similar algorithm such as bubble sort = 1 mark for attempt)

(b) What is the time complexity for the worst-case scenario for this algorithm?

O(n²)

2 marks must include N2 but does not need O


(Fair description - limited understanding = 1 mark)

Question 8

Agent based modelling is an effective modelling tool for certain scenarios.

(a) Name a scenario that agent-based modelling can be used for.

Agent based modelling can be used to mimic and understand how traffic works in cities. In this case,
every car or person is like a little computer character with its own traits and actions. These characters
can talk to each other and react to things like traffic lights, road closures, and anything else that can
make traffic better or worse.

2 marks any example is okay (Fair description - limited understanding = 1 mark)

(b) Explain the benefits of using agent-based modelling for your example named above.

Agent-based modelling allows users to gain insights into traffic congestion, the impact of new road
infrastructure, and strategies for optimising traffic management.

3 marks any two benefits (Fair description - limited understanding = 1 mark)

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 5 OF 31


HIGHER LEVEL Section A (continued)

Question 9

Below are two relational tables in a database.

ID FName SName Year


1 Keith Quille 1
2 Roisin Faherty 2
3 Karen Nolan 3
Year_Tutors

Year_
ID FName SName
Tutor_ID
1 3 Charlie Quille
2 2 Robin Quille
Students

Describe the relational relationship between the tables above.

Table 1 represents teachers and tutors, table 2 represents students. Each table has a primary key.
2 marks description of each table – could be part of overall answer
(Fair description - limited understanding = 1 mark)

Table 1 to table 2 are relational, that is, a year tutor is related to/has students. This is represented by
the foreign key field “Year_Tutor_ID”, for example, Robin Quille has Roisin Faherty as her year tutor.
3 marks linking primary and foreign keys to describe one to many relationship – does not need
to include the words one to many (Fair description - limited understanding = 1 mark)

Question 10

Below is an extract from a US National Cancer Institute post titled 'Can Artificial Intelligence
Help See Cancer in New, and Better, Ways?' (2022). Read the extract carefully and answer the
questionthat follows.
“Two identical black-and-white pictures of murky shapes sit side-by-side on a computer screen.
On the left side, Ismail Baris Turkbey, M.D., a radiologist with 15 years of experience, has
outlined anarea where the fuzzy shapes represent what he believes is a creeping, growing
prostate cancer. On the other side of the screen, an artificial intelligence (AI) computer program
has done the same —and the results are nearly identical.”
Name and describe one ethical consideration and proposed action that you think should be
applied if we are to use AI in the medical domain for predicting cancer.

When we use AI to predict cancer in medicine, we need to worry about two important things (any one
discussion is okay):
Reliability: We want the AI to be good at making predictions, so it doesn’t give the wrong diagnosis or
advice.
Fairness: The AI should treat everyone the same way. If it’s biased and gives different results to
different groups of people, it can create unfair healthcare differences.
2 marks any reasonable ethical issue (Fair description - limited understanding = 1 mark)

One proposed action is to always have humans on the loop, that is, for every prediction there should
be some human oversight to ensure fairness and reliability.
3 must be related to the ethical consideration (Fair description - limited understanding = 1 mark)

PAGE 6 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section A (continued) HIGHER LEVEL

Question 11

Websites are typically not as adaptive as they should be to allow for inclusive use for users with
special/additional needs. Name and describe two elements or design features that you would
implement in a website to support users with additional needs.

Text to speech and speech to text: Functionality can be a huge help to users who have hearing or
vision problems. TTS technology speaks aloud the website’s text content so that users who are blind
can access and comprehend the content. STT, on the other hand, transforms spoken words into
written text, making it possible for people with hearing loss to utilise the website.
3 marks any reasonable element/design feature
(Fair description - limited understanding = 1 mark)

A website will adjust to different devices and user needs if it has a responsive and accessible design.
Users who utilise assistive devices or who have cognitive or mobility problems must understand
this. To accommodate various screen sizes and input methods (mouse, keyboard, touch, and voice),
elements should be correctly scaled, spaced, and arranged.
2 marks any reasonable element/design feature
(Fair description - limited understanding = 1 mark)

Question 12

The below code uses the mean function from the statistics module to find the mean in a list:

myList = [1, 2, 3, 4, 5]
median = statistics.mean(myList)
print(median)

Pattern recognition is the ability to recognise common approaches (such as code) or patterns
within problems you are trying to solve. When you break down (decompose) a problem into
smaller subproblems, you may be able to spot patterns/previous code approaches that will help
you to solve the problem. – adopted from Isaac Computer Science.

Identify one pattern and explain its use if you were to write the code for the statistics.mean
function yourself:

One pattern that would be used to solve this problem to get the mean is a loop to add up all of the
values.

This loop allows us to get the total of all the numbers in the list (a key component of getting the mean).
3 marks any of the two patterns (Fair description - limited understanding = 1 mark)
2 marks explain its role (Fair description - limited understanding = 1 mark)

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 7 OF 31


HIGHER LEVEL Section B Long Answer Questions

Section B Long Questions 78 marks

Answer any two of the three questions.

Question 13 39 marks (7, 15, 17)

(a) What is a recursive algorithm?

A recursive algorithm breaks down a complicated problem into smaller, related problems and solves
each of them in a similar fashion.
3 marks for mentioning smaller parts (Fair description - limited understanding = 1 mark)
4 marks for mentioning smaller parts are similar and overall definition
(Fair description - limited understanding = 2 marks)

(b) Recursion is slower computationally than solving the same problem using a loop, yet
recursion is often the preferred method over a loop for some algorithms such as the
quicksort algorithm, why is this the case?

Two examples are:


Code clarity and reading: When used to solve issues that naturally display recursive behaviour,
recursive algorithms can occasionally result in more succinct and understandable code. For
algorithms like quicksort, the code can closely resemble the problem’s intrinsic structure, making it
simpler to comprehend and maintain. Quicksort breaks down a problem into smaller sub-problems
and solves them recursively.
Similarity to the problem: Recursion can be similar with a problem’s natural structure in some cases.
The divide-and-conquer paradigm, on which Quicksort is built, divides the problem into smaller
subproblems, and this decomposition naturally lends itself to recursion.
7 marks for any one reason (Fair description - limited understanding = 2 marks)
8 marks for a deeper understanding of it, for example, readability or similar to how quicksort
works (Fair description - limited understanding = 2 marks)

PAGE 8 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section B (continued) HIGHER LEVEL

(c) Below is an example of a recursive function for the quicksort algorithm. This algorithm
sorts a list in ascending order. Modify the code to sort the list in descending order. The
first four rows are completed where no modifications were needed.
Modified code – leave blank if
Original code
modification is not needed.
def qS(listIn): -
if len(listIn) > 1: -
pivot = listIn[-1] -
belowPiv =[] -
for item in listIn[:-1]: -
if item < pivot: If item > pivot
belowPiv.append(item) -
abovePiv =[] -
for item in listIn[:-1]: -
if item > pivot: If item < pivot
abovePiv.append(item) -
return qS(belowPiv) + [pivot] +
-
qS(abovePiv)
else: -
return(listIn) -

8 marks for first correct line


8 marks for second correct line
+1 mark for both right with no errors

Question 14 39 marks (6,11,10,12)

(a) The internet allows the world wide web to run on it. This happens in part due to
communication protocols. One such set of protocols that is widely used is TCP/IP.

Explain what TCP is in the transport layer in the TCP/IP protocol stack.

TCP is a standard communication protocol that ensures the reliable and ordered delivery of data
between devices on a network. It establishes a connection before data transfer, manages the flow of
data, and performs error checking to ensure that the information sent from one device is received
accurately by the destination device. TCP is part of the TCP/IP protocol suite, which forms the basis
for communication on the internet.

6 marks based on any definition of the TCP protocol


(Fair description - limited understanding = 2 marks)

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 9 OF 31


HIGHER LEVEL Section B (continued)

(b) IP addresses are used in the internet layer of the TCP/IP protocol stack. The following is
an example of an IP address:
192.168.0.1
(i) What is an IP address?
(ii) As the number of devices connected to the internet grows, identify one issue that
could arise with an IPv4 address as shown above?

An IP address is like a digital ID for devices on the internet, helping them talk to each other. The worry
with IPv4 addresses is that there aren’t enough of them for all the new gadgets we’re connecting.
That’s why there’s a switch to IPv6, which has a lot more addresses, making sure everything stays
connected as we add more devices to the internet.

5 marks for defining an IP address (Fair description - limited understanding = 2 marks)


6 marks for the limitation of the number, IPv6 not needed
(Fair description - limited understanding = 2 marks)

(c) An IP address is often used when cybercrime is investigated. This is part of the TCP/IP
stack. How can an IP address be used in cybercrime investigations?

When investigators are trying to catch cybercriminals, they use something called an IP address. It’s
like a digital ID for devices on the internet. In the tech world, it’s part of the TCP/IP stack, and it helps
figure out where online activities are coming from and going to. So, if someone’s up to no good
online, the investigators can use the IP address to track them down and find out who they are and
where they’re doing their activities.

5 marks for the concept that they are traceable/like an ID


(Fair description - limited understanding = 2 marks)
5 marks for any reason that may aid in cybersecurity
(Fair description - limited understanding = 2 marks)

(d) Interactive information systems are often implemented as a client server model. With
respect to data security, why is a client server model a good choice?

For interactive information systems, using a client-server model is a wise decision for data security
because it comes with a number of benefits:
• It enables unified management of security and makes it simpler to enact regulations and safety
measures.
• Access Control: The server can limit who has access to data, ensuring that only people with
permission can access it.
• Data exchanged between clients and servers can be encrypted to ensure its security while in transit.
• User Verification: Servers can verify a user’s identity and determine if they are authorized to view a
certain piece of data.
• Logging: Servers can preserve thorough records of user behavior that can be used to track and look
into security concerns.

6 marks for any one concept for data security


(Fair description - limited understanding = 2 marks)
6 marks for any second concept for data security
(Fair description - limited understanding = 2 marks)

PAGE 10 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section B (continued) HIGHER LEVEL

Question 15 39 marks (4,12,12,11)

(a) What is the difference between raw data and data transformed for analysis?

Raw data
Unorganised and unprocessed data is referred to as “raw data.” It is the most fundamental type of
data and is meaningless on its own. Various formats for raw data exist, including those for numbers,
text, pictures, and other data types. Examples of raw data include a list of numbers, a collection of
sensor readings, or a string of characters and words in a text file.
2 marks (Fair description - limited understanding = 1 mark)

Transformed data
Raw data is made usable and valuable for decision-making, comprehension, or communication by
providing context, relevance, and structure. In order to make information easier to understand and
use, it is frequently transformed, this may include, fixing problematic data, taking the raw data and
calculating frequencies of occurrence for a bar chat etc.
2 marks, should include one example of transformed data (Fair description - limited
understanding = 1 mark)

(b) The World AnƟ-Doping Agency (WADA) state that “Blood doping is the misuse of certain
techniques and/or substances to increase one’s red blood cell mass, which allows the body
to transport more oxygen to muscles and therefore increase stamina and performance.”

Each year, athletes are tested for increased red blood cells, where the data presented in the
following histogram shows the red blood cell count on the X axis and the number of athletes
on the Y axis.

Do you think that some athletes were blood doping? Analyse the histogram and available
data (mean, mode and median) to support your answer.

There is likely some blood doping going on. The graph is mostly symmetrical (normal distribution) as
the mean, mode and median are similar (students do not need to prove this). There are a group 1-3
people who have a distinctly different red blood cell count, outside of this distribution, and they have
a red blood cell count of ~ 6.5.

4 marks for providing analysis on histogram


(Fair description - limited understanding = 2 marks)
4 marks for using mean, median and mode
(Fair description - limited understanding = 2 marks)
4 marks for bringing together the two previous sets of marks to make a decision
(Fair description - limited understanding 1 mark)

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 11 OF 31


HIGHER LEVEL Section B (continued)

(c) WADA would like you to develop an algorithm that automatically detects if blood doping
occurs based on red blood cell count. By examining the histogram in the Figure from part
b of this question, write an algorithm in pseudocode that will detect athletes are blood
doping assuming that the red blood cell counts are stored in a list such as the one below
(note: the data is in a one dimensional list, call athletes_RBCB that you can reference):

List example:
athletes_RBCB = [4,5.6,4.2, 6.6, 6.4, 4,1]
Hint: Loop through the list and write the pseudo code to identify any possible values that may have
blood doped.

Read in athletes_RBCB as 1d list and same as athletes_RBCB


Iterate through athletes_RBCB: (for each rbc in athletes_RBCB:)
If rbc > 6.25:
Output -> blood doping may have occurred
Else:
Output -> blood doping may not occurred

4 marks for reading in list (Fair description - limited understanding = 2 marks)


4 marks for looping through and checking (Fair description - limited understanding = 2 marks)
4 marks for conditional value and output (> 6.1-6.5 would be acceptable) (Fair description -
limited understanding = 2 marks)

(d) False predictions are often made by such algorithms. A False Positive (FP) is where an
athlete that is predicted as blood doping but did not, and a False Negative (FN) is where an
athlete is predicted as not blood doping but was.
Briefly describe, basing your answer on ethics, which of the above predictions (a False
Positive or a False Negative) is worse for the WADA.

The least desirable error for the World Anti-Doping Agency (WADA) would be a False Negative (FN).
A False Negative happens when an athlete is expected to not be blood doping but is actually blood
doping in the context of WADA’s aim to detect and prohibit doping in sports. False Negatives are
typically viewed as more harmful in the context of anti-doping efforts because they allow doping to
go undetected and undermine the fundamental principles of fair play in sports. False Positives (FPs)
are also problematic because they can unjustly damage an athlete’s reputation, trigger investigations,
and potentially harm their career.

3 marks for showing understanding of the meanings of FN and FP


(Fair description - limited understanding 2 mark)
5 marks for comparing and selecting which one and why
(Fair description - limited understanding 2 mark)
3 marks for why not FP or at least why it is the lesser of the two negative outcomes
(> 6.1-6.5 would be acceptable) (Fair description - limited understanding = 2 marks)

PAGE 12 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section C HIGHER LEVEL

Section C Programming 87 marks

Answer all question parts.

Question 16 (43 marks)

(a) Surveys are common practice, and analysis of such surveys is often essential to gain an
understanding of data collected, transforming it into information. This survey was data
collected by asking people the county they were from and their monthly rent. This was to
determine national and country average rent rates. This survey only included people from
Dublin, Kildare and Laois.
Open the program called Question16_A.py from your device.
Enter your name on line 2.

# Enter name:

county = [“Dublin”, “Laois”, “Dublin”, “Dublin”, “Dublin”, “Dublin”,


“Dublin”, “Kildare”, “Laois”, “Kildare”, “Dublin”, “Laois”, “Dublin”]

rent = [2500, 1200, 2000, 2100, 1900, 1999, 1790, 1500, 1000, 1390, 1980,
1105, 1999]

# Part i

# Part ii

print(“-”*18)
print(“{:<12}”.format(“County”)+”{:<12}”.format(“Rent €”))
print(“-”*18)
for index in range(len(county)):
print(“{:<12}”.format(county[index])+”{:<12}”.format(rent[index]))

# Part iii

# Part iv

This way the data is stored is that each index (0, 1, 2 …) in each of the two lists (county and
rent) holds corresponding data. That is the first element of each list is a response from the
same person. The list county records their county and the list rent records how much their
monthly rent is. For any analysis in this question, you must assume that the lists could be
larger, so you must calculate all values using code, they must not be hard coded.

The program currently loops through the list and prints to the screen each survey response:

----------------------------
County Rent €
----------------------------
Dublin 2500
Laois 1200
Dublin 2000

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 13 OF 31


HIGHER LEVEL Section C (continued)

Modify the program to do the following:

(i) Where Part i is a comment in the code, write code to calculate and print the total number
of survey responses that the study has collected. When the program is run, it may look as
follows:
The total people in the survey is: 13

print(“The total people in the survey is:”, len(county))

2 marks (1 mark for determining the length and 1 for printing)

(ii) Where Part ii is a comment in the code, write code to take in and store another survey
response from the user, you must take in their county name and monthly rent and
add them to the appropriate lists. You can assume that the user will always enter one of
the following counties (in the correct case, that is, first letter uppercase and the rest lower
case) Dublin, Kildare and Laois. When the program is run, it may look as follows:

Please enter your county: Laois


Please enter your monthly rent amount: 2000

surveyCounty = input(“Please enter your county:”)


surveyRent = int(input(“Please enter your monthly rent amount:”))

county.append(surveyCounty)
rent.append(surveyRent)

10 marks (3 marks for each entry and variable type, and 2 marks each for appending to
the correct lists)

(iii) Where Part iii is a comment in the code, write code to calculate and print the average rent
across all three counties (rounding to two decimal places).

averageRent = sum of the values / number of values.

When the program is run, it may look as follows:

Average Rent for all counties: € 1747.36

averageRentAll = sum(rent) / len(rent)


print(“\n\n”)
print(“Average Rent for all counties: €”, round(averageRentAll,2))

10 marks (6 marks for calculating the average rent, 4 marks for printing)

PAGE 14 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section C (continued) HIGHER LEVEL

(iv) Where Part iv is a comment in the code, write code to calculate and print the average rent
for each of the three counties Dublin, Kildare and Laois (rounding to two decimal places).
When the program is run, it may look as follows:

Average Rent for Dublin: € 2033.5


Average Rent for Kildare: € 1445.0
Average Rent for Laois: € 1326.25

dublinRents = []
kildareRents = []
laoisRents = []

for index in range(len(county)):


if county[index] == “Dublin”:
dublinRents.append(rent[index])

if county[index] == “Kildare”:
kildareRents.append(rent[index])

if county[index] == “Laois”:
laoisRents.append(rent[index])

print(“\n”)
# Dublin
averageRentDublin = sum(dublinRents) / len(dublinRents)
print(“Average Rent for Dublin: €”, round(averageRentDublin,2))

# Kildare
averageRentKildare = sum(kildareRents) / len(kildareRents)
print(“Average Rent for Kildare: €”, round(averageRentKildare,2))

# Laois
averageRentLaois = sum(laoisRents) / len(laoisRents)
print(“Average Rent for Laois: €”, round(averageRentLaois,2))

21 marks (7 marks per average broken into: 4 marks for getting totals, 2 marks for
calculating the average (using length in this example) and 1 mark for printing)
Note: this was one example of determining the average rent for each of the three
counties, other methods applicable, 7 marks per county applies.

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 15 OF 31


HIGHER LEVEL Section C (continued)

Question 16 (42 marks)

(b) The infinite monkey theorem states that a monkey hitting keys at random on a typewriter
keyboard for an infinite amount of time will almost surely type any given text, including
the complete works of William Shakespeare.
Open the program called Question16_B.py from your device.
Enter your name on line 2.

# Enter name:

import random

targetWord = “T”

def monkeys_typing():
guessNumber = random.randint(65, 90)
letter1 = chr(guessNumber)
count = 1
guess = letter1
print(guess)

while guess != targetWord:


guessNumber = random.randint(65, 90)
letter1 = chr(guessNumber)
guess = letter1
print(guess)
count +=1
return count

print(monkeys_typing())

This monkeys_typing function is designed to return the number of times it takes a monkey
to guess characters (mimicking the infinite monkey theorem for a limited amount of text)
until it guesses the letter T. Please note the random number guesses the ASCII range for
upper case letters, and converts them to characters to compare against the desired
output, the letter T.

Modify the program to do the following:

(i) For this part, do not modify the function, modify the main body code to run the function
three times and get an average of how many guesses are needed to type the letter T. An
example output would be:

Average number of guesses for three runs is: 107.33

run1 = monkeys_typing()
run2 = monkeys_typing()
run3 = monkeys_typing()

average = (run1+run2+run3) / 3
print(“Average number of guesses for three runs are:”, average)

22 marks broken into:


• 10 marks for each of the three guesses (not this could be done using a list)
• 6 marks for calculating the average (2 marks each)
• 6 marks for printing

PAGE 16 OF 31 HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024


Section C (continued) HIGHER LEVEL

(ii) Modify the function to identify how many guess it may take to generate the word “THE”,
note you will also have to modify the variable: targetWord = “THE”. An example output
would be:

Average number of guesses for three runs is: 18148.0

import random

targetWord = “THE”

def monkeys_typing():
guessNumber = random.randint(65, 90)
letter1 = chr(guessNumber)
guessNumber = random.randint(65, 90)
letter2 = chr(guessNumber)
guessNumber = random.randint(65, 90)
letter3 = chr(guessNumber)
count = 1
guess = letter1+letter2+letter3
print(guess)

while guess != targetWord:


guessNumber = random.randint(65, 90)
letter1 = chr(guessNumber)
guessNumber = random.randint(65, 90)
letter2 = chr(guessNumber)
guessNumber = random.randint(65, 90)
letter3 = chr(guessNumber)
guess = letter1+letter2+letter3
print(guess)
count +=1

return count

run1 = monkeys_typing()
run2 = monkeys_typing()
run3 = monkeys_typing()

average = (run1+run2+run3) / 3
print(“Average number of guesses for three runs are:”, average)

20 marks (10 for the three guesses, 10 for combining and comparing).

HIGHER LEVEL COMPUTER SCIENCE | Pre-Leaving Certificate, 2024 PAGE 17 OF 31

You might also like