Tuesday 21 May 2024
Afternoon (Time: 2 hours)
Paper
reference 1CP2/02
Computer Science
PAPER 2:Application of Computational Thinking
You must have:
• computer worksttion with pproprite progrmming lnguge code editing softwre
and tools, including an IDE that you are familiar with which shows line numbers
• a ‘STUDENT CODING’ folder containing code and data files
• printed and electronic copies of the Program Language Subset (PLS) document (enclosed).
Instructions
•• Answer all questions on your computer.
Save the new or amended code in the ‘COMPLETED CODING’ folder using the
name given in the question.
•• Do not overwrite the original code and data files provided to you.
You must not use the internet at any time during the examination.
Information
•• The total mark for this paper is 75.
The marks for each question are shown in brackets
– use this as a guide as to how much time to spend on each question.
• The ‘STUDENT CODING’ folder in your user area includes all the code and data files
you need.
Advice
•• Read each question carefully before you start to answer it.
Save your work regularly.
• Check your answers and work if you have time at the end.
Turn over
P75441A
©2024 Pearson Education Ltd.
F:1/1/1/1/1/1/1/1
*P75441A*
, Answer ALL questions.
Suggested time: 10 minutes
1 A program is written to provide information about the rainbow.
Colours and wavelengths are stored in arrays. For example, the colour Violet is
produced when the wavelength is from 380 to 424
The user enters an index and the colour at that array location is displayed. The user
enters a wavelength and the colour for that wavelength is displayed.
Open file y
Amend the code to:
• fix the syntax error on original line 5
waveTable = [380, 425, 450, 492, 577, 597", 622]
• fix the NameError on original line 6
found = falsese
• fix the syntax error on original line 8
wavelength = 012323
• fix the syntax error on original line 15
index = int (input ("Enter an index: ")
• fix the NameError on original line 21
color = rainbow[index]x]
• fix the ValueError on original line 22
print (int (colour))
• fix the logic error on original line 26
if ((wavelength < 380) and (wavelength > 622)):
• fix the logic error on original line 29
index = 11
• fix the logic error on original line 35
elif (waveTable[index] <= wavelength):
• fix the logic error on original line 37
print (rainbow[index - 2])
Do not change the functionality of the given lines of code.
Do not add any additional functionality.
Save your amended code as Q01FINISHED.py
(Total for Question 1 = 10 marks)
2 P75441A
, Suggested time: 15 minutes
2 A program encrypts a message using a Caesar cipher.
The letters of the alphabet are shifted a set number of places. A positive shift moves
the letters to the right. A negative shift moves them to the left.
Blanks, symbols and numbers are not encrypted.
When the end of the alphabet is reached with a positive shift, shifting continues at
the start of the alphabet. When the start of the alphabet is reached with a negative
shift, shifting continues at the end of the alphabet.
For example, a shift of −2 encodes the plaintext letter P to the ciphertext letter
.
A shift of +4 encodes the plaintext letter X to the ciphertext letter B.
When working correctly, the program produces the encrypted ciphertext for these
plaintext messages and shift inputs.
Plaintext Shift Ciphertext
The Rainbow 4 Xli Vemrfsa
Alphabet Soup −5 Vgkcvwzo Njpk
123 ^&* Bye 9 123 ^&* Khn
Amend the code to make the program work and produce the correct output.
You will need to:
• choose between alternative lines of code. Make a choice by removing the # at the
beginning of the line you choose to execute
• run the program with the data from the table and check it meets the
requirements.
Do not change the functionality of the given lines of code.
Do not add any additional functionality.
Save your amended code as Q02FINISHED.py
(Total for Question 2 = 10 marks)
P75441A 3
Turn over