Programming exam - paper 2 - practice test 1
Task instructions
● You should use your PLS regularly during these tasks.
● Read the questions in this document and then update the .py files as required.
● Do not modify the code files in any other way. Just answer the questions.
● Do not add extra functionality or features unless told otherwise.
● Do not change the basic structure that you are given unless told otherwise.
● Do not change the names of variables or functions unless you are told otherwise.
● The number of marks for each question is shown in brackets.
● Do NOT add input validation code unless you are told otherwise.
● Do NOT add blank lines to the files...the reference to line numbers will break.
If you are working on coding rooms then you do NOT need to save the file as
Q1Finished.py etc.
If you are working on a raspberry pi computer then you should save the file as
Q1Finished.py in the FINISHED CODING folder for each of these tasks/questions
Demo Question 1
A program is to be written that will generate 8 random integers between 1 and 15 (inclusive).
The program will store the generated numbers in a list and then print them out. The output
of the program will look exactly like this : (please note your random numbers will be
different!)
Some of the code has been written for you already, but it is not fully finished.
Open DemoQ1.py and make the required changes to make the program fully work :
1) Complete the import statement at the top of the code. This will allow us to generate
random numbers later on in our code. (1)
2) Finish the lines of code that initialise both NUM_NEEDED and MAX_NUM. (2)
3) Finish the line of code that initialises ourList to the empty list. (1)
4) Complete the first line of the for statement so it loops the correct number of times
using the correct constant mentioned above. (1)
5) Complete the append statement inside the for loop. (1)
6) Fix the issue that is preventing the title from printing properly (1)
7) Fix the lines of code that are supposed to print “Start” and “End” (2)
Save your final .py file as DemoQ1Finished.py in your FINISHED CODING folder.
(Total marks 9)
Question 1
A program is to be written that asks the user for their name and surname and then prints a
suitable greeting. The program then prints the length of the user’s surname.
Typical output
Open Q1.py and make the required changes to answer the following questions:
1) Complete all three lines of code to ensure that the two strings are initialised to the
empty string and the lenOfSurname is initialised to zero. (3)
2) Fix the two input statements so that they work properly. (2)
3) Fix the welcome message so the concatenation works properly. (1)
4) Correct line 37 so that the len() function correctly assigns a value to the
lenOfSurname variable. (1)
5) Fix the print statement on line 39 so it correctly prints out the length of the user’s
surname. (1)
Save your final .py file as Q1Finished.py in your FINISHED CODINGfolder.
(Total marks 8)
Question 2
A program is to be written that asks the user to type 25, then square roots it and prints the
answer. It then does the same thing with 144. This is done using the correct Python square
root function that is imported from the correct module.
Typical output
Open Q2.py and make the required changes to answer the following questions:
1) Import the correct module to allow the square root function to be used later on. (1)
2) Create the two global variables num2 and squareRoot2 and initialise them both to zero. (2)
3) Fix line 25 so it assigns num1 with an integer as opposed to a string. (1)
4) Fix line 27 so it correctly calls the correct square root function and hence assigns
squareRoot1 with the integer 5. (1)
5) Now fix lines 32 and 34 so the code correctly uses an input statement to assign the num2 the
integer 144 and the correct square root function is used to assign squareRoot2 with the value
of 12. (2)
6) Finish the code for the print statement on line 35 so it correctly prints the desired output as
shown above. (3)
Save your final .py file as Q2Finished.py in your FINISHED CODINGfolder.
(Total marks 10)
Question 3
A program is to be written that asks the user for 5 numbers and each is square rooted using
a new function called MySquareRoot() that has been partially written for you. Each answer
is added to a list and the list is then printed out at the end. The words “The end” are then
printed as a final message.
Typical output
Open Q3.py and make the required changes to answer the following questions:
1) Fix the import statement on line 5 so square roots can be calculated later in our code. (1)
2) Create the NUM_OF_ROOTS constant and initialise it on line 9. (1)
3) On line 14, create the variable theList and initialise it to the empty list. (1)
4) Add one correctly named parameter to the function header on line 25. (1)
5) Fix the function return on line 27. (1)
6) Fix the for loop on line 33 so it loops the correct number of times using the correct
constant(1)
7) Fix the append statement on line 37. (1)
8) Fix the first line of the for loop on line 40 so all answers will print out correctly.(1)
9) Fix the print statement on line 43.(1)
Save your final .py file as Q3Finished.py in your FINISHED CODINGfolder.
(Total 9 marks)
Question 4
A fully working program has been written that asks the user for 6 numbers and calculates
the mean. It prints a title, uses a for loop to get the input data and then prints out the list of
input numbers and the final answer as shown in the output image below:
Typical output
Open Q4.py and make the required changes.
In this question you may not add or change any of the code. All of the code is written for you, but the
order of the lines has been jumbled up. Rearrange the various lines of code so the algorithm works
out the mean of the numbers in the list and prints out the final answer.
All jumbled lines have been moved to the bottom of the file. You need to move them back up into
their correct positions. Do not change any of the lines of code...just move them!
Do not add any additional functionality.
HINT: use CRTL-X and CRTL-V to move code around. (This is known as “cut and paste”)
Save your final .py file as Q4Finished.py in your FINISHED CODINGfolder.
(Total marks 9)
Question 5
A program is to be written that works out the volume of a cuboid if you tell it the length, width
and height as integers. The answer will be an integer. This program will use a procedure to
calculate and print the answer out.
Typical output
Open Q5.py and make the required changes.
1) Change line 14 so that the someWidth variable is initialised properly. (1)
2) Complete the body of the PrintCuboidVol() procedure so it produces the behaviour discussed
at the top of this question and shown in the output image. (6)
3) Fix the procedure call on line 45 so the arguments are passed in correctly. (1)
Save your final .py file as Q5Finished.py in your FINISHED CODINGfolder.
(Total marks 8)
Question 6
A program is to be written that asks the user how old they are now and then tells them how old they
will be in 3 years time. It should have a suitable underlined title and a goodbye message at the end.
Your output should be formatted exactly as shown in the desired output below.
Desired output
Constants and variables to be used
Name constant or Data What is it used for?
variable? type
NUM_OF_YEARS Constant int A constant to store the number 3. We are
finding out the user age in 3 years time!
someAge Global variable int A variable used to store the age of the person
now.
in3Years Global variable int A variable used to store the age of the person
in 3 years time.
Open Q6.py and make the required changes.
1) Using the constants and variables discussed in the above table, you need to adjust the code
in Q6.py so that it meets all of the requirements discussed above. Your output should look
exactly like the desired output shown above.
Save your final .py file as Q6Finished.py in your FINISHED CODINGfolder.
(Total marks 7)
Question 7
A program is to be written that prints out the “times tables” for any given number.
It should ask the user which times table they want and how many numbers they would like to see.
Your code should exactly match the output shown below in terms of formatting.
You do not have to use a subprogram, but will score more points if you do.
Desired output
You must use the variables and constants shown in this table.
Constants and variables to be used
Name constant or Data What is it used for?
variable? type
APP_NAME Constant string Used to store the name of the application which
is ”Times table - trial version V1.5”. This can
then be printed out in the title and at the end
after the times tables are printed.
theTimesTable Global variable int Will be used to store the number that is the
times table that the user wants to print out. If
they want to see the 8 times table then this
variable will contain the integer 8.
numOfValues Global variable int Will be used to store how many of the times
table to print out. If the user wants to see the
first 12 things in the times table then this
variable will have the integer 12 inside it.
Open Q7.py and make the required changes.
You must use the variables and constants shown in the table above to implement the requirements
discussed at the beginning of this question. Your output should look exactly like the desired output
shown.
Save your final .py file as Q7Finished.py in your FINISHED CODINGfolder. (Total marks 9)
CHALLENGE SECTION
This is not part of the practice test, but will be a helpful reminder of the Python Turtle module.
For each of the next few questions, you should use the standard coding template from the S: drive to
make a .py file and call it Q8.py, etc.
Each question is worth 9 marks. You should use functions/procedures where appropriate.
Questions are marked like this:
Question 8
Make this red square with a blue outline.
Save your final .py file as Q8Finished.py in your FINISHED CODINGfolder.
(Total 9 marks)
Question 9
Make this square target shape with the correct colours and equal size sections.
Save your final .py file as Q9Finished.py in your FINISHED CODINGfolder.
(Total 9 marks)
Question 10
Write code that will make this “flower” drawing.
Save your final .py file as Q10Finished.py in your FINISHED CODINGfolder.
(Total 9 marks)
Finished?
1. Make sure all questions are fully answered and you have uploaded the 11 .py files including
the demo.
2. You may help other students if you want to.
3. You may want to revise other areas of computer science from this page. Remember to scroll
down and remind yourself about the Year 9 content too!
https://qs-wgsf.fireflycloud.net/computer-science/qegs-comp-sci-site/year-10---2021