Specimen programming tasks – Python

a program I built to experiment with writing to and reading from files

code I created to play with file input/output

It’s time I started trying out Python to do various tasks, so I’ve started with the specimen tasks for OCR GCSE Computing, as available from their website.  Unfortunately, I can’t really post anything on here about the actual bank of live tasks, but the specimens could make a good start and are publicly available.

There are three tasks in the specimen booklet: the first is to create a maze game in Scratch, and this I’ve totally ignored as it’s the sort of task I start my year 7s on when I first cover Scratch with them, so not really any kind of challenge at all.

The second task proved rather more interesting to tackle, as it asks for a system to check for a password that passes certain tests.  I found there’s flexibility in the task to extend it, as it is vague enough in places to allow for easier or more detailed specifications; it gives examples of how weak, medium and strong passwords could be interpreted, but does not rule in or out using non alpha-numeric characters. The task itself was straightforward: I used a while loop to keep going through the program until the user requests to stop, another while loop to keep asking until the password is the required length, then step through it character by character to check for instances of upper case, lower case and numeric characters, by using ord(e) to obtain the numerical value of the character first.  I use boolean values to check the occurrence of  each type of character, then assign a value of Strong, Medium or Weak as suggested in the task specification.

The third task is proving the most challenge.  This involves writing to and reading from a text file.  At first glance it seems fairly straightforward to do this in Python – open a file in read, write or append mode.  In write mode you create a new file if it doesn’t already exist and wipe the existing content if it does.  In append mode you add text to the end of the file.  In read mode you read back the text in the file, either as a whole or line by line.

The issue I have is how to interpret the requirements of the assignment, and what tools to use.  My programming is such that I can usually do more or less what I need to, but not necessarily in the most efficient way.  For this task I have a choice of techniques, it seems: I can either write plain text to the file, read it back in and then fiddle with it to get it in a format I can use, or I can use a module called pickle which is designed to save objects.  This is more efficient than the previous way but uses its own structure rather than purely reading to and writing from a plain text file.

Another issue is that the specification says that the program needs to locate data in the file by name and highest score, delete an item and associated data from the file and locate and update a high score.  This seems to suggest that the processing should be integrated with the reading and writing of the file, rather than reading in data, processing it and then resaving it in bulk.  Of course I’m not even yet aware of whether Python allows you to amend the contents of the file rather than simply reading or writing.  I’ve a strange feeling it doesn’t.

One source of help on this is the web of course, and I’m still in the process of exploring these resources – I’ve found several forums talking of exactly the same sort of task as this, and wonder if I can find similar threads around for the actual live assignments – that’s something that bodes watching carefully, and any suspicion of plagiarism would need to be counteracted by making sure students understand and can explain the code – after all, there’s nothing wrong with research solutions as a way to learn, but what mustn’t happen is just copying solutions wholesale without understanding.

From what I’ve seen of the model assignments for this qualification, it appears to be generally the tasks that involve reading to and writing from files that provoke the most questions of interpretation, and now I understand why!  At least I’ve learnt a lot from playing with my own code today and have a deeper understanding of the issues needed for answering the assignment tasks.


About emmyleigh
Writer/editor/proofreader who loves technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: