Hi,
I have been looking at the specimen Higher Coursework, specifically the program part . We use Python 3.5. I have a solution I think, but when I look at the marking scheme it specifies that records should be used. I understand that records are part of the theory for the course but my program seems to work fine with a pair of parallel lists/arrays. Has anyone else had a go at this in Python using records or does anyone have an opinion on whether it is ok in a coursework task to use parallel arrays? I have attached a solution and would welcome any constructive criticism/feedback given that I am not the sharpest tool in the shed when it comes to programming!
It is time this question of Python and records/arrays of records was given some official response. I can’t see how a solution using two parallel arrays is any worse than one using an array of records. All the Python schools won’t be too happy if no mark will be awarded for using parallel arrays rather than an array of records. Why doesn’t SQA just come out and say that if you use Python then you cannot get all the marks available for the coursework, which is what the marking scheme suggests? And what would the justification be?
In my opinion, it’s not just a Python issue. It’s this whole business of whoever it is creating these tasks not really paying any attention to what they are doing. There is no mention of records anywhere in the entire programming task, yet there appears to be 3 or 4 marks dedicated to the existence of a record structure, despite the fact that records wouldn’t be the first structure I’d opt for, nor would I expect anyone else to.
At most it should be 1 mark, and that’s only IF it had already been mentioned in the task. Since it hasn’t, it should be worth zero marks and full marks should be awarded to anyone who has used parallel arrays (which would by my first choice of structure).
There really is no reason to create a record structure to hold 2 pieces of data – and that goes for ANY programming language.
100% agreed with @leemurray here. I wouldn’t create a record structure for the problem either.
Also agree with calls for an official response on this. Has anyone e-mailed yet in regards to Python/Records in the coursework? Found that Greg & Raymond reply fairly quickly usually.
To be honest, beyond perhaps stating in the Coursework that some kind of record structure should be used, I don’t see the problem with the requirement to use some form of array of ‘records’. It’s not a particularly tricky thing to implement in Python (a list of dictionaries or a list of objects derived from a simple class structure). It IS Higher after all. The benefit in general of an array of records is that it keeps the data for each record together as a collection – making the data management (deletion, addition, editing) easier rather than splitting it up into what I think is an un-intuitive way across parallel arrays.
Thanks for the advice guys and for your views on the matter. I’ll pop an e-mail out to Greg and Raymond. Must be getting old, every new change/increase in challenge that comes in makes me feel like even more of a dunce! I’m off to an Understanding Standards session next week so hopefully that will ease some of my anxiety.
On the supplied structure diagram it has beachData(name,rating) getting passed around. That is what I think the pupils are meant to use to work out it’s a record (list of lists). 4 marks is a lot to lose if you miss it.
Sean
This is not an “Official Response” but, on the arrays of records issue – if candidates use appropriate constructs within the language available, that will be ok – so in Python, an array of objects or a list of lists would be acceptable (and acceptable to anyone marking from SQA).
Charlie
I know it’s a tough one to answer (especially unofficially), but what about a list of dictionaries? Or a list of tuples? I’m guessing the answer would be “as long as it’s like an array of something that can store multiple values”.
I don’t know why there isn’t just a set way to do it. Why not prescribe the accepted method of creating records in Python? I understand it’s probably because there are so many languages out there and it’s not really practical to prescribe methods for however many languages are being used, but if you prescribe the method for 1 or 2 languages that don’t support records, then that would give much better guidance on how to do it in general.
I have never understood the fear of prescribing teaching and learning when, in the end, the exam and coursework are prescribed tests of what has been taught and learned.
I have a solution similar to Fraser and it works fine. however, I would like to use the named Tuple that is available in version 3.7. The issue I have is trying to get a fixed loop to enter the values into the ‘fields’ in the named tuple…. Any Ideas?
Haven’t done the task, I’ve been doing Records in Python 2.7 as tuples and reading in (see below), even found “array._replace” has worked on letting me initialise and add data later or change data in fields like “accountDetails[x] = accountDetails[x]._replace(balance = accountDetails[x].balance – 25.00)”
——-
from collections import namedtuple
def readInAcountData():
accountDetails = []
num_accounts = 0
bank_acc = namedtuple(‘bankaccount’,’name, balance, pin’)
accountFile = open(“accountdetails.csv”,”r”)
for line in accountFile:
row_data = line.split(‘,’)
current_record = bank_acc(name=row_data[0], balance=float(row_data[1]), pin=int(row_data[2]))
accountDetails.append(current_record)
num_accounts = num_accounts + 1
accountFile.close()
return accountDetails, num_accounts
———————————
Haven’t done the task, I’ve been doing Records in Python 2.7 as tuples and reading in (see below), even found “array._replace” has worked on letting me initialise/add data later or change data in fields like “accountDetails[x] = accountDetails[x]._replace(balance = accountDetails[x].balance – 25.00)”
——-
from collections import namedtuple
def readInAcountData():
accountDetails = []
num_accounts = 0
bank_acc = namedtuple(‘bankaccount’,’name, balance, pin’)
accountFile = open(“accountdetails.csv”,”r”)
for line in accountFile:
row_data = line.split(‘,’)
current_record = bank_acc(name=row_data[0], balance=float(row_data[1]), pin=int(row_data[2]))
accountDetails.append(current_record)
num_accounts = num_accounts + 1
accountFile.close()
return accountDetails, num_accounts
———————————
In my opinion there are two really good options for creating record-like structures in Python 3.
You have namedtuples (from the typing library rather than collections) which allows you to set type ‘hints’ – here is an example (it won’t let me embed) https://repl.it/@mcwhim/Arrays-of-Records-Example)
And new in Python 3.7 is data classes which solve the problem of immutability, which was mentioned above. For more info see https://realpython.com/python-data-classes/
I just found that Repl.it (even though it uses 3.6.1) will allow you to import dataclasses. I’ll be using them to teach records from now on.
I’ve already taught records, but I’ll use repl.it later on when we need to go over it again.
Thanks for reminding me of dataclasses, Marc.
You must be logged in to reply to this topic.