Inft1004 Assignment 2009 s1t1 School of Electrical Engineering and Computing Inft1004 Introduction to Programming – Assignment 2 Due 11.59pm on Sunday 9 May; students are advised to start work...

1 answer below »
Inft1004 Assignment 2009 s1t1
School of Electrical Engineering and Computing


Inft1004 Introduction to Programming – Assignment 2

Due 11.59pm on Sunday 9 May; students are advised to start work immediately

Weighting 30%

Paired work Students are strongly encouraged to work in pairs on this assignment

Your assessment task
For this assignment you are to write a Python program that analyses results from the Simon
Questionnaire for Understanding Aspiring Politicians (SQUAP). This is a questionnaire designed to
assess potential politicians and suggest what positions they might be best suited for. It has just
seven questions, each of which has eight possible answers. Here are three example questions. (You
might find it fun to devise your own questions, but we don’t need all seven.)
When a question makes me feel uncomfortable, I tend to respond by:
(a) explaining that it makes me feel uncomfortable, then answering to the best of my ability
(b) staring blankly at the questioner as if they were stupid
(c) answering the question that I would have preferred them to ask me
(d) saying that I will respond after seeking advice from the relevant department
(e) attacking the questioner, for example by saying that their question is stupid
(f) responding that the question should be answered by a member of the opposing party
(g) saying the first remotely relevant thing that comes to my mind
(h) looking at my watch, excusing myself, and leaving
When a politician in my party is accused of profiting from questionable land deals:
(a) I decline to comment because that should be the role of the party leader
(b) I express empathy with any victims of the alleged behaviour
(c) I decline to comment because the accusation should be investigated by the police
(d) I suggest that it is in keeping with the politician’s past behaviour
(e) I express my dismay at the accusation, and hope that it will prove to be unfounded
(f) I remind the public and the press of similar accusations against members of other parties
(g) I call on the media to say nothing about the accusation until it is established as fact
(h) I call on my party to bring in measures to avert such behaviour in the future
My perspective on taxation is that
(a) it should be entirely abolished
(b) I have thought of a far better way to administer it
(c) it is a way of helping to distribute a country’s wealth
(d) it is a necessary contribution to the cost of running the country
(e) it is probably unfair, but is a reasonable way of raising funds
(f) it is easily avoided with the right accounting techniques
(g) it is a blight on the wealthy, forcing them to support those who won’t support themselves
(h) politicians should be exempt because they already contribute in other ways
Now this is not a standard multiple-choice questionnaire. Rather than choosing just one option for
your answer, you are given ten points for each answer, and you divide them as you wish among the
eight options. So for example, for the first question you might simply give all ten points to option b;
whereas for the third question you might give five points to g, three points to h, and two points to a.

Inft1004 Introduction to Programming Assignment 2 2
Your task is to write a Python program to process people’s answers to this questionnaire and let
them know which political roles they seem best suited for.
For the purposes of the program, the answer to a single question will be a set of eight integers, the
points allocated to each of the options a to h. If somebody gives all ten points to option b, their
answer to that question will be XXXXXXXXXX; if somebody gives five points to g, three points to h,
and two points to a, their answer to that question will be XXXXXXXXXX.
Once the program has the answers to all seven questions for a person, it puts them into the
following grid. Notice that the cells of this grid are not in the order a to h: rather, each cell explicitly
indicates which value goes into it. For example, in the first cell of question 6 the program will put
the value for question 6 option e; in the second cell of question 6, the value for option d; in the third
cell, the value for option f; and so on.
Question RL RM RB LL LM LB CR CL
1 b: c: e: f: d: h: g: a:
2 c: f: a: b: g: e: d: h:
3 f: g: h: c: b: d: a: e:
4 h: a: c: d: e: b: f: g:
5 a: e: d: g: h: f: b: c:
6 e: d: f: a: c: g: h: b:
7 g: h: b: e: f: a: c: d:
Here is a full example. If somebody gives the following answers to the seven questions (let’s call
them the raw answers) . . .
Question 1: XXXXXXXXXX
Question 2: XXXXXXXXXX
Question 3: XXXXXXXXXX
Question 4: XXXXXXXXXX
Question 5: XXXXXXXXXX
Question 6: XXXXXXXXXX
Question 7: XXXXXXXXXX
. . . the grid will be filled as follows . . .
Question RL RM RB LL LM LB CR CL
1 b: 0 c: 0 e: 0 f: 3 d: 0 h: 4 g: 0 a: 3
2 c: 0 f: 0 a: 0 b: 0 g: 0 e: 3 d: 0 h: 7
3 f: 0 g: 0 h: 1 c: 0 b: 0 d: 5 a: 0 e: 4
4 h: 0 a: 0 c: 0 d: 1 e: 3 b: 1 f: 0 g: 5
5 a: 1 e: 1 d: 1 g: 0 h: 0 f: 0 b: 2 c: 5
6 e: 0 d: 0 f: 0 a: 1 c: 1 g: 5 h: 0 b: 3
7 g: 0 h: 0 b: 0 e: 5 f: 3 a: 0 c: 0 d: 2
Total XXXXXXXXXX
The program then sums the values in each column, and looks for the two biggest values. In this case
they are the CL column, with 29, and the LB column, with 18. These columns are then used to
indicate what political roles the person seems best suited to.
While the assignment will undoubtedly seem daunting at first, we have broken it into a number of
tasks, each of which is described in the sections below. If you tackle just one task at a time, and
don’t move on until you have completed that task, you might be surprised at the program that you
will eventually produce.


Inft1004 Introduction to Programming Assignment 2 3
Journal
As programming is a complex task, you are required to maintain and submit a journal, a separate
word-processed document that includes:
• A title page
o Assignment heading and description
o Team members’ names, student numbers, lab sessions
• An entry for each session of work on the assignment
o Day, time, and date; eg Day 1: Monday 1 April, 10-11am
o Which aspects of the assignment are worked on
o Which bits are done by which member(s) of the pair
o Questions that arise, difficulties that you encounter, and how you overcome them
• Conclusion
o An overall conclusion for the journal
o What was not completed, and why
o Lessons that you have learnt
o Suggestions for students in the next offering of this course to help them complete the
work
o References to any external person or source that you use (in a consistent style, such
as APA where appropriate)
• Footers
o With your names and page numbers
By the time you’ve finished the program your journal will probably be many pages long. The
journal is intended to record your design thoughts, your programming thoughts, and the time you
spend on the task, so you must keep it up to date at all times. A ‘journal’ that is thrown together a
few days before the assignment is due is not a journal at all.
When you hand in your files, your journal must be a pdf file.

Cover sheet – not required
The university does not require cover sheets for online submissions.

Files and folders
When you hand in the assignment you will be handing in two files: your Python program and your
pdf journal. There is a particular structure that you are required to follow.
Both files (and no other files) will be in a folder whose name is your names, without spaces,
followed by the abbreviation Assgt2. If Abby Archer and Zeke Zammit are working together, their
folder will be called AbbyArcherZekeZammitAssgt2.
Within that folder, your Python program will have your names followed by Assgt2.py (eg
AbbyArcherZekeZammitAssgt2.py); and your journal will have your names followed by Journal.pdf,
(eg AbbyArcherZekeZammitJournal.pdf). Remember that the journal is to be a pdf file.

Problem solving
Several aspects of this assignment involve problem solving. This is not unusual: it is difficult to
specify programming tasks that do not require problem solving. While you might be tempted to just
write some code and hope that it will eventually do what you want it to do, in the end it will be far
more effective to first work out exactly what you want the code to do, and only then start writing
the code.
Based on past experience, students who believe that they are having trouble with their program code
are generally having trouble with their program design, their algorithm. If your program isn’t doing
Inft1004 Introduction to Programming Assignment 2 4
what you want it to do, this is probably because you haven’t solved the problem and clearly worked
out how the program should do what you want it to do. You are most unlikely to get the program
working correctly if you haven’t correctly solved the problems and designed the solutions.
When you need to problem-solve, the key is not to search the web for inspiration, it is not to
randomly try things in the hope that one of them will work: it is to write down what you have, to
write down what you want, and to think about how to get from the first to the second. It often helps
to draw diagrams. It definitely helps to discuss the problem, and possible solutions, with your
partner. If you actually solve the problem for yourself, rather than finding something somewhere
that you might be able to bend into a solution, it will be a huge step in your development as a
programmer.


Programming in a pair
Programming with a partner is almost always more effective than programming alone. The
programming is more effective, because there are two minds working on the same problems; and
the learning is more effective, because each of you learns from the suggestions made by the other.
Pair programming is most effective when the partners are sitting together at the same computer.
However, that is not always practical, so here are some other suggestions.
If you could share the coding environment, you could both work with it at the same time.
Unfortunately, Rodeo is not a cloud-based environment, and you cannot both work on the same
Rodeo program at the same time from different locations. If you are working at the same time, you
will each need to be working on your own copy of the program.
You can email the program to each other, or share it on a file-sharing site such as Microsoft Teams.
If you do this, you need to be careful with version control. If you are working at the same time on
two different versions, it can be hard to combine them into a single version later. Also, the
university’s email system blocks emails with .py extensions, so before sending the file as an email
attachment you should either remove its extension altogether or change it to something that the
email system thinks is innocuous, such as .doc. This will be much easier if you have your operating
system set to show file extensions.
When you need to discuss the program, you might be able to use software that permits you to share
screens with one another. One person can share a screen with the Rodeo program in it, and you can
both discuss the same screen by phone or by some other voice medium such as Skype.
These are just suggestions, and you should work to develop your own ideas for how you can most
effectively work together if you cannot meet up in the same location.

A general suggestion
It’s really important to tackle one task, one function, at a time. At first the whole assignment will
seem overwhelming. But by doing one function at a time, one task at a time, you will find it much
easier to come to grips with – although of course some tasks will be tougher than others. So long as
you start early enough, you should complete most of the tasks.


Assignment tasks

Task 1: analyse_csv(filename, filetype): read a preprocessed csv file – 5 marks
We’ll start somewhere moderately simple. Rather than the raw answers shown above, we will have
a csv file containing preprocessed answers: answers that have already been translated into the grid.
For the example shown above, this csv file will contain the following eight rows:
Inft1004 Introduction to Programming Assignment 2 5
Lee Ping Hai
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
This file has been made available to you, as CandidateAnswers1Preprocessed.csv.
The first task for your program is to write a function called analyse_csv() that will read this csv
file into a list of strings which will then be sent off for further processing. The first argument of the
function will be the file name; the second is irrelevant for now, but call it filetype, and when calling
the function, make the second argument "preprocessed".

Tip: setting the default directory
You know that to access a file by its file name you need to set the default directory to where that
file is located – and each time you open Rodeo, you need to set the default directory again. A
quicker way to set it is with a cd (change directory) command in the terminal; however, to do that
you need to know the directory path.
Here’s the tip: change the default directory once using the file navigation system – and observe that
it actually puts the cd command into the terminal. Copy that command, paste it into a comment near
the start of your program, and add a backslash before every backslash in it. Then for example,
you’ll have a comment like this:
# Directory change: cd "C:\\Uni\\Inft1004\\Assessments\\Assignment2"
Next time you open Rodeo and want to change to that directory, just copy the comment from ‘cd’
onward, paste it into the terminal, and press Enter. Note that the line must be a comment, not a
command to be executed when you run the script. If it’s a command rather than a comment, it will
generate an error when we try to load your program to mark it, because that particular directory
won’t exist on our computers.

Task 2: process_candidate(candidate, file_lines, filetype): form a list of lists of
numbers – 7 marks
The second task is to transform the data from a list of comma-separated strings into a list of sublists
for other parts of the program to work on.
The list that is returned should be a list of lists of the numbers, one sublist for each row, like this:
[[0, 0, 0, 3, 0, 4, 0, 3], [0, 0, 0, 0, 0, 3, 0, 7], [0, 0, 1, 0, 0, 5, 0, 4],
[0, 0, 0, 1, 3, 1, 0, 5], [1, 1, 1, 0, 0, 0, 2, 5], [0, 0, 0, 1, 1, 5, 0, 3],
[0, 0, 0, 5, 3, 0, 0, 2]]
This is not a trivial task. You will need to consider what each line of the input file actually looks
like as text; you will need to separate its components; you might need to be wary of the end-of-line
character; you will need to work out how to form a list of the eight numbers in each row; and you
will need to work out how to form a list of those lists.
While it might seem that the best way to discover these things is by desperately searching the web,
it’s actually the case that the answers are all in the material we have covered so far in the course,
including the exercises; you just have to think about how to apply that material to this new problem.
Inft1004 Introduction to Programming Assignment 2 6
You can ignore the candidate parameter for now, but when calling the function, use 0 as the
corresponding argument. The argument corresponding to file_lines will be the list of strings
produced in analyse_csv(), and filetype will be the same value that was passed in to
analyse_csv(). So at the end of analyse_csv(), add a command such as
process_candidate(0, file_lines, filetype).

Task 3: echo_answers(candidate_name, answer_list, filetype): display the input – 4
marks
Write the function echo_answers(), which takes three arguments: the name of the candidate, the
list of lists of numbers produced by process_candidate(), and the file type (which is currently
‘preprocessed’). The data should now be displayed like this:
Questionnaire answers (preprocessed) for Lee Ping Hai
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
The first line of the output includes both the candidate’s name and the file type; each subsequent
line starts with ‘Q’ and the question number, then displays the eight numbers that make up the
preprocessed answers for this candidate.
Add a command near the end of process_candidate() to call echo_answers().

Task 4: analyse(answer_list): work out the totals for the eight columns – 10 marks
Write the function analyse(), which takes one argument: the list of lists of numbers produced by
process_candidate(). This function will work out the column totals, and will return a list of two-
element sublists in which the first element is the two-letter abbreviation of a political role and the
second element is the total score in the column associated with that role.
For the example that we have been using, the function will return the list [['rl', 1], ['rm', 1], ['rb', 2],
['ll', 10], ['lm', 7], ['lb', 18], ['cr', 2], ['cl', 29]] – the same abbreviations and totals that we saw in the
grid at the start of this specification.
You will need to give some thought to how to add the numbers in each ‘column’, as the numbers
are in different sublists of a list, not in an actual grid.
Add a command near the end of process_candidate() to call analyse(). As analyse() returns a
list, the command will need to assign the returned list to a variable.

Tip: void functions and fruitful functions
Just as it’s important to remain aware of the type of every variable, it’s important to be aware of the
type of every function. If a function is void – it doesn’t return anything – it is called as a statement
in its own right. If it is fruitful – it does return something – it is called as an expression, which is
evaluated, and something appropriate is done with the result. Often, it will be assigned to a variable.
For this assignment we are asking you to write nine or ten functions, some of which are void and
some of which are fruitful. For each function, be aware of which type it is, so that you know how it
should be called.


Inft1004 Introduction to Programming Assignment 2 7
Task 5: display(column_totals): display the column totals and the corresponding roles
– 7 marks
Each of the nine possible roles has a two-letter abbreviation and a full name, as follows:
rl: Leader of a major right-wing party
rm: Minister or shadow minister in a major right-wing party
rb: Backbencher in a major right-wing party
ll: Leader of a major left-wing party
lm: Minister or shadow minister in a major left-wing party
lb: Backbencher in a major left-wing party
cr: Crossbench member inclined to support the right wing
cl: Crossbench member inclined to support the left wing
cn: Genuinely non-partisan crossbench member
Write a function called display(), which takes the list of column totals as its argument, and begins
by creating a dictionary of the two-letter abbreviations and the corresponding names.
Once the dictionary has been created, display() will use the list of column totals to display the
totals and the corresponding role names. For our example, it will print this:
Possible roles, with indicative scores:

1: Leader of a major right-wing party
1: Minister or shadow minister in a major right-wing party
2: Backbencher in a major right-wing party
10: Leader of a major left-wing party
7: Minister or shadow minister in a major left-wing party
18: Backbencher in a major left-wing party
2: Crossbench member inclined to support the right wing
29: Crossbench member inclined to support the left wing
Remember, the ninth role doesn’t have a corresponding column, so it doesn’t have a score. We’ll
deal with that later.
Add a command near the end of process_candidate() to call display().

Task 6: sort_descending(column_totals): sort column totals by total, descending – 4
marks
Write a function called sort_descending(), which takes the list of role abbreviations and column
totals as its argument and returns a similar list in which the roles are in descending order of total.
For example, given the list [['rl', 1], ['rm', 1], ['rb', 2], ['ll', 10], ['lm', 7], ['lb', 18], ['cr', 2], ['cl', 29]],
it will return the list [['cl', 29], ['lb', 18], ['ll', 10], ['lm', 7], ['rb', 2], ['cr', 2], ['rm', 1], ['rl', 1]].
Add a command near the end of process_candidate() to call sort_descending(), then ensure
that the call to display() acts on the newly sorted list
The display() function should then print this:
Possible roles in order of suitability, with indicative scores:

29: Crossbench member inclined to support the left wing
18: Backbencher in a major left-wing party
10: Leader of a major left-wing party
7: Minister or shadow minister in a major left-wing party
2: Backbencher in a major right-wing party
2: Crossbench member inclined to support the right wing
1: Minister or shadow minister in a major right-wing party
1: Leader of a major right-wing party
Inft1004 Introduction to Programming Assignment 2 8
Students who are not yet good at problem solving might immediately turn to the web to find out
how to sort a list of sublists by the second element of each sublist in descending order. They might
well find something, and it might well be somewhat involved. On the other hand, students who have
started to apply the techniques of problem solving might think along the following lines. Exercise 8
in the week 5 notes explicitly talks about how one might sort a list of two-element sublists by the
second element. If the elements in each sublist are swapped, the standard sort() method might
then take care of it. As for sorting in the opposite order: if you don’t like the order resulting from
the sort() method, you could then apply the reverse() method.

Task 7: the genuinely non-partisan crossbench member – 4 marks
A genuinely non-partisan crossbencher is indicated not a by a score in a particular column, but by
having every column total less than 12. If that is the case, the genuinely non-partisan crossbench
member role will be ranked top, with the other roles still in their existing order. Because there is no
column total, the program will instead use the word ‘Top’. Here is an example, from a different
candidate.
Questionnaire answers (preprocessed) for Isabella Sounder
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX

Possible roles in order of suitability, with indicative scores:

Top: Genuinely non-partisan crossbench member
11: Backbencher in a major right-wing party
10: Leader of a major right-wing party
10: Crossbench member inclined to support the right wing
9: Minister or shadow minister in a major right-wing party
9: Backbencher in a major left-wing party
8: Leader of a major left-wing party
8: Crossbench member inclined to support the left wing
5: Minister or shadow minister in a major left-wing party
In display(), after setting up the dictionary and printing the heading for the candidate, find the
maximum column score. If it’s less than 12, print the genuine non-partisan crossbencher line. The
function will then proceed to display the ranked column totals and roles as before.

Task 8: the role descriptions – 7 marks
The file called RoleDescriptions.txt contains the nine two-letter role abbreviations and a multiline
description of each role. The system should now be adjusted to display these descriptions for the top
two column scores. Here is an example, with the descriptions shortened to save space.
Questionnaire answers (preprocessed) for Lee Ping Hai
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX
Q XXXXXXXXXX

Best suited roles in order of suitability, with indicative scores and role
descriptions:

Inft1004 Introduction to Programming Assignment 2 9
29: Crossbench member inclined to support the left wing
A crossbencher is a politician who is either independent or associated
with a party that is highly unlikely to attain government in its own
right.
More description of crossbenchers here.

18: Backbencher in a major left-wing party
A major party is likely to be either in government or the main
opposition party.
A main purpose of backbenchers is to contribute to the number of seats
required for the party to attain majority and govern the country.
More description of backbenchers here.

Remaining roles in order of suitability, with indicative scores:
10: Leader of a major left-wing party
7: Minister or shadow minister in a major left-wing party
2: Backbencher in a major right-wing party
2: Crossbench member inclined to support the right wing
1: Minister or shadow minister in a major right-wing party
1: Leader of a major right-wing party
Write a function called read_roles(), which has no parameters. This function will read the file
RoleDescriptions.txt and set up the two-letter abbreviations and their multiline descriptions in a
suitable structure: this might be a list of sublists, where each sublist has two elements, the
abbreviation and the description; or it might be a dictionary. Whatever structure the function
creates, it should then return it. It might be helpful to know that the only lines in the file that
consists of just two letters (and an end-of-line character) are the abbreviations; so when you find
such a line, you know that the preceding description has finished.
Write a function called describe_role(), which takes a single argument, the two-letter
abbreviation of a role. This function will call read_roles() to set up the structure of abbreviations
and descriptions, and will then print the description corresponding to the abbreviation that was
provided as its argument.
You might notice that the role abbreviations in the grid and in RoleDescriptions.txt are in upper
case, while in much of this specification we have used lower-case versions. When comparing the
abbreviation from the list with the one from the file, it might be wise to allow for differences in
case.
Adjust display() so that for the top two roles it prints the role description after the column score
and role name; then it displays the remaining roles as before. It should first call describe_role()
for the genuine crossbencher role if that one is selected; but it will still go on to describe the top two
of the remaining roles.

Task 9: the role descriptions continued – 4 marks
As described, the system prints descriptions of a candidate’s top two column scores. But what if the
third-ranked column has the same score as the second? What if the fourth-ranked column has the
same score as the second? While it’s unlikely, a candidate might contrive to get seven scores of 8
and one of 4. That candidate would clearly be a genuinely independent crossbencher, but would
then have seven equal highest column scores – all of which should therefore come with
descriptions.
Adjust your code for task 8 to determine whether any subsequent columns have the same column
score as the second-ranked one, and, if so, to display their descriptions as well.



Inft1004 Introduction to Programming Assignment 2 10
Task 10: multiple candidates’ answers in the same file – 6 marks
So far we have been working with csv files that contain the name and answers of a single candidate.
However, for the sake of human efficiency we would like to combine the names and answers of
several candidates into a single file.
Back in analyse_csv() we told you to use 0 as the candidate number when calling
process_candidate(). Now is the time to expand on that. Once you have read all the lines from
the csv file, you can trivially work out how many candidates are represented in the file. You can
then set up a loop to process each candidate in turn, using the loop index as the candidate number in
the call to process_candidate().
Each time process_candidate() is called, it will need to know which lines of the file apply to the
candidate it is processing. That’s also trivial: you know the candidate number, and you know that
each candidate takes eight lines, so you can work out which lines to process for candidate n.
You might first try this on CandidateAnswers123Preprocessed.csv; then, once you have it working,
on CandidateAnswersAllPreprocessed.csv.

Task 11: raw data – 14 marks and Task 12: empty cells – 3 marks
All this time we’ve been working with preprocessed data: the candidates’ actual answers have
already been shifted into columns corresponding to the specified roles. But that’s not the way the
questionnaire was set up: otherwise candidates would quickly learn that if they gave all their
answers to, say, options d, f, and h, they would be observing some form of consistency. Instead, the
answers for each question are jumbled, and we need the grid (remember the grid?) to work out
which answer for each question goes into which column.
It’s now time for you to implement the grid. Write a function called translate(), that takes the list
of answer lists produced in process_candidate() and returns a list of the same form, but
translated onto the grid. When we showed you the grid, we also showed you the raw answers that
we have since been using in their preprocessed form. With that example, which is in the file
CandidateAnswers1Raw.csv, process_candidate() would produce and echo the list [[3, 0, 0, 0, 0,
3, 0, 4], [0, 0, 0, 0, 3, 0, 0, 7], [0, 0, 0, 5, 4, 0, 0, 1], [0, 1, 0, 1, 3, 0, 5, 0], [1, 2, 5, 1, 1, 0, 0, 0], [1, 3,
1, 0, 0, 0, 5, 0], [0, 0, 0, 2, 5, 3, 0, 0]] (the candidate’s actual answers to the questionnaire), but
would then call translate(), which would produce the list [[0, 0, 0, 3, 0, 4, 0, 3], [0, 0, 0, 0, 0, 3,
0, 7], [0, 0, 1, 0, 0, 5, 0, 4], [0, 0, 0, 1, 3, 1, 0, 5], [1, 1, 1, 0, 0, 0, 2, 5], [0, 0, 0, 1, 1, 5, 0, 3], [0, 0, 0,
5, 3, 0, 0, 2]].
This translation need not involve a great deal of code – perhaps a dozen lines of Python – but it will
involve a great deal of thought, of problem solving. As one of the steps, you might find it useful to
create yet another list of lists, this one representing in some way the order of the answer letters for
each question: for example, for question 1, a list that represents the order b c e f d h g a, as found in
the first row of the grid.
You should be able to work this out, but the list returned by translate() should be assigned to a
variable, and it is that list that should now be analysed, sorted, and displayed.
You should also have worked out that when you call analyse_csv() with a raw file, the file type
should be ‘raw’; remember that the file type is passed to process_candidate(), which will use the
file type to decide whether the answers need translating to the grid.
But there’s a catch: as you’ll see if you open them, the raw csv files include blank cells. These are
likely to cause problems when you try to form a list of numbers; so while producing the list of
numbers from the list of strings in process_candidate(), your program will need to replace any
blank entries with zeros.
Inft1004 Introduction to Programming Assignment 2 11
Once you have completed these tasks, your program should work just as well on all the raw files as
on the preprocessed files.

Assumptions: well-behaved data
A ‘real’ program of the sort described here would need to include checks for many things that could
go wrong with the data that it is given. A csv file might have the wrong number of lines; it might
have the wrong number of entries in each line; the first entry on an answer line might not be of the
form Q and a digit (would that matter?); the answer elements might not all be numbers; the numbers
in a row might not add up to 10; the candidate’s name might be missing; and so on.
For this assignment you may assume that the data files are all well behaved: that they have none of
these problems, and that your program does not need to check for them.

Note regarding global variables
The Inft1004 text book explains how to use global variables, but we have advised that it is best to
use them only when really necessary. This assignment, as specified, does not require any global
variables; you are therefore advised not to use any.
Assessment criteria
Your work will be assessed out of 100 marks. In addition to the 75 marks listed above with the task
descriptions, there will be marks for
• your journal, as specified above, clearly showing the design and development process (12)
• program style, including well-named variables and appropriate and useful comments in the
code (13)
Once these marks have been allocated, marks will be deducted for the following:
• failure to follow instructions/requirements, eg with file names
• syntax errors or runtime errors in your program
• failure to fully and clearly reference any material from external sources, such as code
written by other people or code with which other people have assisted you
• late submission – see below
If you get code from other people or sources, or if other people help you with your own code, you
must add comments making this clear, and explain it in your journal. If the marker uncovers
evidence that you have cheated in any way, for example, by sharing your code with others in the
class, or by getting help from anyone other than your partner and not referencing it, the matter will
be reported to the Student Academic Conduct Officer as a potential case of academic misconduct.
(See Academic integrity below.)

Handing in your work
You are to hand in the assignment electronically using Blackboard’s Assignment facility. Because
you need to hand in a whole folder and its contents, you are required to zip the files together.
Remember, you are to hand in a folder containing exactly two files: your Python program and your
pdf journal.
When you zip your folder and its contents, in way that preserves their directory structure, be sure
that you produce a .zip file, not some other format such as a .rar file. (If you’re at all unsure about
this, tell your operating system to display file extensions as well as file names.) There are many
zipping software packages, some commercially available, some free, and some provided with
operating systems. Well before you submit your assignment, be sure that you have access to
appropriate software and know how to use it. Once you have zipped your files together, be sure to
Inft1004 Introduction to Programming Assignment 2 12
unzip them to a new location to check that they unzip correctly. Also be sure that the zip file has the
same name as the folder, your names without spaces followed by Assgt2; for example,
AbbyArcherZekeZammitAssgt2.zip.
When you are ready to submit your zipped file, log in to Blackboard, go to the site for this course,
and follow these steps . . .
• Select the Assessment folder.
• Click the Assignment 2 link, which will take you to the appropriate upload page.
• Under Assignment submission, click Browse my computer (next to Attach files), and navigate
to your zip file. Alternatively, just drag the zip file from where it’s located into the dashed
rectangle. In the comments field put your name and your partner’s name.
• When you’ve done that, click the Submit button.
• If you don’t see a message saying the assignment is complete, go back and check that you’ve
done all these steps.
• If you want to submit an updated version of the assignment, go back to the Assignment link
and click Start new submission on the assignment’s Review submission history page. Make
sure you’re aware of the deadline: the final marking will be applied only to the most recent
submission, and if it’s submitted late it will be marked as late.
You might be required to demonstrate your program, and to explain aspects of your code, in a
subsequent lab class.

Paired work
When two students work as a pair, all folders and files (as described above) should clearly indicate
the names of both students in the pair. Only one copy of the work needs to be handed in, only one
journal needs to be handed in (a combined journal for the pair), and both students in the pair will
normally get the same mark for the assignment, regardless of who did how much of the work,
unless it is clear that this would be a serious injustice.

Deadline and consequences for late submission
The assignment is due by 11.59pm on Sunday 9 May, the end of week 9 of classes. Work will be
penalised 10% for every day or part day by which it is late.
Students are encouraged to aim to complete the assignment well before the deadline, as
programming assignments are well known for taking far longer than the students expect.

Academic integrity – getting assistance or code
This assignment is your chance to gain an understanding of fundamental concepts of program
structure and coding syntax on which later learning will be based. It is important that you master
these concepts yourself.
Since you are mastering fundamental skills, you are permitted to work from the textbook and course
examples, but you must acknowledge assistance from other textbooks or classmates. In particular,
you should try not to use code or algorithms from external sources, and not to obtain help from
people other than your instructors, as this can prevent you from mastering these concepts. However,
if you do get code or assistance from these external sources, you must ‘attribute’ it: both in your
journal, and in comments in your code, you must clearly explain where or who the code or
assistance came from, and how much help or code was provided.
Here is a detailed guide to who you can get help from, and where you can get code from. Please pay
careful attention to it.
Inft1004 Introduction to Programming Assignment 2 13
Assistance: who might you want help from? Status
Yourself, your partner Highly encouraged
Your lecturer, your tutor Encouraged
Classmates, other tutors Attribution required
Online forums, relatives, friends, other students not in this course Not acceptable
Any other sources Ask the lecturer

Resources: where might you want to get code from? Status
Course textbook, course notes and examples, your partner Encouraged
Other textbooks Attribution required
Online programs, hired coders, relatives, friends, other students Not acceptable
Any other sources Ask the lecturer
Obtaining code or assistance for which attribution is required without attributing it, or obtaining any
code or assistance from sources marked ‘Not acceptable’, is a breach of academic integrity, and can
be referred to the Student Academic Conduct Officer for investigation. Furthermore, providing such
code or assistance is also a breach of academic integrity, and can be treated as such.
If you do receive code or assistance for any of the assignment, there is a specific way in which you
must provide the attribution in your program. We call this a reference comment.
The reference should say whether it is for externally sourced code, an externally sourced algorithm,
or personal assistance. It should be given a unique identifier so that its end can be clearly marked.
The beginning and end of each reference should be marked in a particular way that stands out from
the code. In the examples below we use lines of hash symbols to do this.
Each reference should include:
• its purpose: why was external code or assistance sought?
• the date the code or assistance was used;
• the source of the code or assistance;
• the author of the code, if known, or the person providing assistance;
• the url, if applicable;
• any adaptation that was required to incorporate external code;
• a brief description of assistance that was provided, if applicable.

Here are some examples.
#############################################
# Reference A3: externally sourced algorithm
# Purpose: sort a list of sublists by the second element in each sublist, descending
# Date: 1 Apr 2021
# Source: Python documentation
# Author: Andrew Dalke and Raymond Hettinger
# url: https://docs.python.org/3/howto/sorting.html
# Adaptation required: changed variable names; saw need to assign result to original list name
#############################################

freqList = sorted(freqList, key = lambda wordFreq: wordFreq[1], reverse = True)

#############################################
# End reference A3
Inft1004 Introduction to Programming Assignment 2 14
#############################################



#############################################
# Reference C5: externally sourced code
# Purpose: make a list consisting of sublists
# Date: 2 Apr 2021
# Source: stackoverflow
# Author: Dzarafata
# url: https://stackoverflow.com/questions/ XXXXXXXXXX/create-list-of-sublists
# Adaptation required: changed variable names
#############################################

This is where the copied code goes

#############################################
# End reference C5
#############################################



#############################################
# Reference P7: personal assistance
# Purpose: deal with 'list index out of range' error
# Date: 5 Apr 2021
# Source: fellow student Susan Piper
# Assistance: explained that these errors arise if we try to access an element beyond the end of the list
#############################################

This is where the newly modified code goes

#############################################
# End reference P7
#############################################

School of Electrical Engineering and Computing
Inft1004 Introduction to Programming – Assignment 2
Answered 2 days AfterMay 06, 2021INFT 1004University Of South Australia

Solution

Pratap answered on May 08 2021
33 Votes

"""
SQUAP Result Analyser Program
"""
def analyse_csv(filename, filetype):
"""
Function to read the input file
and store the lines as list
:param filename:...

Submit New Assignment

Copy and Paste Your Assignment Here