Version: 2025/03/19 10:22
CSC1015F Assignment 5B (70 Marks)
Arrays
Learning Objectives
By the end of this lesson, you should be able to:
• Be able to use while loops effectively in your programs.
• Create a list of items
• Perform the common operation on a list.
• Manipulate lists.
• Use the common List Functions.
• Use Lists in a Function.
• Understand what a multi-dimensional list is.
• Understand what a Dictionary is.
Assignment Instructions
This assignment involves constructing Python programs that manipulate lists, dictionaries and strings.
You can use the following built-in functions in Python: map( ), math.sqrt( ), split( ),
list( ), min( ), max( ).
NOTE Your solutions to this assignment will be evaluated for correctness and for the following
qualities:
• Documentation
o Use of comments at the top of your code to identify program purpose,
author and date.
o Use of comments within your code to explain each non-obvious functional
unit of code.
• General style/readability
o The use of meaningful names for variables and functions.
• Algorithmic qualities
o Efficiency, simplicity
These criteria will be manually assessed by a tutor and commented upon. In this assignment, up to
10 marks will be deducted for deficiencies.
Page 1 of 3
Version: 2025/03/19 10:22
Question 1 [15 marks]
Write a program called ‘missing_number.py’ that takes in a list of arbitrary numbers (separated
by spaces) and outputs a missing number in the sequence.
For example, given the following arbitrary list of numbers (separated by spaces), 88 90 91 92 93 94.
The missing number, 89, is the difference between the expected sum of the numbers and the actual
sum of the numbers.
Assume the lowest and highest numbers given are the range of numbers.
Sample IO (The input from the user is shown in bold font – do not program this):
Enter an array of numbers (separated by spaces):
73 67 68 66 71 70 72
Missing number: 69
Sample IO (The input from the user is shown in bold font – do not program this):
Enter an array of numbers (separated by spaces):
65 60 63 61 64 62
There is no missing number.
Question 2 [20 marks]
Write a program called ‘rearranged.py’ that rearranges a sorted array such that the largest
element is at index 0, the smallest at 1, the second largest at index 2, and so on. You MUST update
the list. Do not create a new list.
You may not use any built-in functions to answer this question.
HINT:
• Use two pointers:
o One at the start (low) for the smallest element.
o One at the end (high) for the largest element.
• Alternate between picking the largest and smallest elements while constructing the new
order.
Sample IO (The input from the user is shown in bold font – do not program this):
Enter sorted numbers separated by spaces:
99 105 120 121 132 145 150 165 170 188 195
Rearranged array: [195, 99, 188, 105, 170, 120, 165, 121, 150, 132, 145]
Sample IO (The input from the user is shown in bold font – do not program this):
Enter sorted numbers separated by spaces:
12 15 22
Rearranged array: [22, 12, 15]
Page 2 of 3
Version: 2025/03/19 10:22
Question 3 [15 marks]
Write a Python program called duplicates.py, in which the user can enter a list of values
(separated by spaces), and these values are then printed in the same order but without duplicates.
You may not use any built-in functions to answer this question.
Sample IO (The input from the user is shown in bold font – do not program this):
Enter an array of numbers (separated by spaces):
6 5 2 9 7 6 2 5 8 4 2 6 9 5 4 7 5 3 5 4 8 9 3 5 9
Unique element array: [6, 5, 2, 9, 7, 8, 4, 3]
Question 4 [20 marks]
Write a program, gridio.py, that allows a user to input integer values and query a 2-dimensional
array of size 9 X 9. Your program should then ask the user for a pair of coordinates, (x, y), separated
by a space and return the value at the position specified by the given coordinates.
For instance, 0 3 should return the value 7 (the value at row one, column four – bearing in mind that
array indices start at zero).
Assume that each integer is a single digit from 1 - 9. Enter -1 for either coordinate to end the
program.
Sample IO (The input from the user is shown in bold font – do not program this):
Enter an array:
359716482
867345912
413928675
398574126
546281739
172639548
984163257
621857394
735492861
Enter coordinates:
0 3
Value = 7
Enter coordinates:
5 5
Value = 9
Enter coordinates:
8 8
Value = 1
Enter coordinates:
-1 -1
Submission
Create and submit a Zip file called ‘ABCXYZ123.zip’ (where ABCXYZ123 is YOUR student number)
containing missing_number.py, rearranged.py, duplicates.py and gridio.py.
Page 3 of 3