Scavenger Hunt Task

  • David Muir
    Participant

    stratton posted a message asking for help with python and the Scavenger Hunt task. When I had a go at this task, I assumed the message file supplied was a csv file. So, I imported the csv module, wrote the code and when it didn’t quite work, had a closer look at the message.txt file. My issue is the fourth message which is: “A prickly problem, Scotland’s national symbol – bit.ly/1q3REpQ” – The problem is the comma after “problem”! I wondered if this was the SQA being nasty and trying to force pupils into writing their own parser but no, I think they just messed up. Why? Exhibit B – the fifth message has a misplaced comma: “-3.188942,W” – so the W ends up at the start of the following message instead of the end of the longitude. On the assumption that it was not a deliberate mistake, I edited message.txt to create message.csv. (I’ll post it to the documents section along with my attempt at a python program.) The code I had written then worked as expected.

    Questions: What do you think? Is this legitimate? Do we need to clear using an edited version of message.txt with the SQA?

    Next, stratton said he was trying a list of dictionaries. I looked at dictionaries but couldn’t get my head around them. Initially, I used lists of lists and pretended it was like a record structure but I wasn’t happy. I was already pretending lists were arrays. Pretending they were records too felt like a virtual step too far. 🙂 Elsewhere on these forums, Peter Thoresen suggested using classes to simulate records and this made more sense to me. Didn’t do it last year but intending to show new Higher that method.

    Questions: Has anybody used classes as records with pupils already? How did they take to it?

    I thought the program was reasonably straightforward but the web section initially looked a bit more tricky. Eventually decided I was over-thinking it and a couple of fairly simple solutions are possible but I am worried that I have made it too simple and would appreciate comments.

    First, as far as I can see, pupils are not expected to detect which css layout is required and swap automatically. I think all that is required is a couple of minor edits to the supplied css to produce two slightly different versions. I think it took me about ten minutes to edit the given css file to produce the required layouts. Is it really that simple or am I missing something? The auto select version is not much more complex but I am not convinced it is necessary.

    Questions: Is it sufficient to produce two edited css files? Should pupils be encouraged to use an auto select method?

    The button to show the plain text message also looked tricky at first. I thought I might have to do a PHP/SQL type solution but Google came to the rescue. A quick search revealed a fairly simple piece of javascript that can be used to show the message. The problem with that approach is the text around the button stays the same (i.e. “Click here to decrypt the message”). I toyed with using a similar method to fix that too but then thought of a much simpler solution. Instead of messing about with Javascript, just link the button with an html tag to a plaintext version of the html page. This feels too simple for Higher but as far as I can see fulfils the brief.

    Questions: (Last ones!) If a pupil came up with the link method, should they be encouraged to use something like Javascript instead or should I just give them the marks for meeting the requirements?

    I’ll post the Python program, my css files and both the Javascript and html solutions in the document area. Comments and questions welcome.

    David Muir
    Participant

    For some reason I am getting: “There was a problem saving your file, please try again.” when I try and upload my solution. I will try again from a different computer tomorrow.

    Sean Stratton
    Participant

    I have tried uploading my solution as well and it would let me upload it even as a ZIP.

    Here is what I came up with (python 3,4), I also used a edited text file.


    # Mr. Stratton
    # SQA Higher Computing Science
    # Assignment: Scavenger hunt v3

    # List of dictionaries

    ”’
    Notes
    I will read in each line then split it up using the commas,
    before storing this in a seperate dictionary for each record inside a list
    ”’

    ”’
    Program Design

    1. Set up variables
    2. read records from file
    3. browse records
    4. end
    ”’

    def readFile(fileName,records):
    #Read in the file a line at a time and store it in a record
    textFile=open(fileName,mode=”r”,encoding=”utf-8″)
    for line in textFile:
    records.append({‘latitude’:line.split(“,”)[0],’longitude’:line.split(“,”)[1],’message’:line.split(“,”)[2]})

    def displayRecord(records,item):
    code=””
    print(”


    Item: %s


    ” %item)
    print(“latitude:”, records[item])
    print(“longitude:”,records[item])
    print(“message:”,records[item])

    for letter in records[item]:
    code+=chr(ord(letter)+2)
    print(“code:”,code)
    print(”


    “)

    def menu():
    choice=””
    while choice not in(“p”,”n”,”q”):
    print(“(p) Previous, (n) Next, (q) Quit”)
    choice=input(“>”).lower()
    return choice

    def browseRecords(records):
    quit=False
    item=0

    while not(quit):

    displayRecord(records,item)
    choice=menu()
    if choice==”p”:
    if item==0:
    item=len(records)-1
    else:
    item=item-1
    elif choice==”n”:
    if item==len(records)-1:
    item=0
    else:
    item=item+1
    elif choice==”q”:
    quit=True
    else:
    print(‘invalid choice’)

    def main():

    fileName=”messages.txt”
    records=[]
    readFile(fileName,records)
    browseRecords(records)

    main()

    Sean Stratton
    Participant

    Well that was a waste of space 🙁 sorry my formatting was removed.

    Mrs Janet McDonald
    Participant

    Hi

    Sorry, I haven’t looked at Scavenger Hunt, but we are using Python to teach the new Higher so I have looked at tackling your second question; dealing with records.

    Like you we are already pretending that lists are arrays… When it comes to records we are using the SimpleNamespace structure. It seems to work quite well and the code you end up with in Python is close enough to Haggis for the kids to follow fairly easily. Thus to define a record called “patient” with fields “forename”, “surname”, “age”, “hometown”, “height”:

    import types
    patient = types.SimpleNamespace()

    patient.forename = “Fred”
    patient.surname = “Jones”
    patient.age = 15
    patient.hometown = “Bathgate”
    patient.height = 170.10

    and you can set up “arrays” of such “records” too.

    David Muir
    Participant

    Hello stratton

    Thanks for your solution. Copy and paste followed by some editing and five minutes later I was able to run your program anyway despite CompEdNet’s helpful reformatting!

    There are a couple of differences in your approach compared to mine the biggest of which is I encipher all the messages and store the cipher version in the record along with the plain text whereas you run the cipher routine every time you display the message. The wording in the assignment says: “Encode the messages… when they are displayed”, which suggests doing it the way you have but as you could display the same message over and over again, it made more sense to me to encipher once and store the result. (On a side note the SQA correctly refer to the message a a cipher, so the pedant in me wants to encipher it, not “encode it!).

    As I said above though, I defined and used a class to use as a record substitute. The relevant section of code (minus formatting I suspect) is shown below. Slightly different syntax to your solution but essentially working the same way.

    # Create a ‘record’ class
    class clue:
    latitude = “” # String record field
    longitude = “” # String record field
    plain_clue = “” # String record field
    cipher_clue = “” # String record field
    # End record class

    # Subroutine: read clue information from text file
    def get_clues():
    # Initialisations
    filename = ‘messages.csv’
    clue_array = [] # Create empty array for clues

    # Check file exists and open file for reading
    if not os.path.exists(filename):
    print(‘The file’, filename, ‘does not exist. Quitting…’)
    sys.exit()
    csv_file = open(filename, mode=”r”, encoding=”utf-8″)

    # Read whole file
    reader = csv.reader(csv_file)

    # Process one row at a time
    clue_num = 0 # Initialise integer variable for loop
    for row in reader:
    clue_array.append(clue()) # Add empty record to array
    # Fill record fields from the row data
    clue_array[clue_num].latitude = row[0]
    clue_array[clue_num].longitude = row[1]
    clue_array[clue_num].plain_clue = row[2]
    clue_num += 1

    # Close file
    csv_file.close()

    return clue_array

    David Muir
    Participant

    Couldn’t upload to the Documents area, but noticed an “Upload document” link, in the forums… so here goes nothing.

    {Update} Curses! Message posted (after a long and promising pause) but no sign of the zip file. 🙁

    David Muir
    Participant

    Hello j.mcdonald

    Thanks for this. A quick poke about suggests simplenamespace (which I hadn’t come across before) is a variation of named tuples (which I had looked at but didn’t use for reasons that now escape me). Don’t know enough about Python to pronounce on a preferred option: tuples or classes. Any Python experts out there who can weigh in with opinions/explanations/examples?

    Ross Ritchie
    Participant

    I’m uploading a guide I made detailing how I would attempt the ISDD section of the assessment. We are not going to run with this one and are doing Choral Shield instead

    David Muir
    Participant

    Hello Ross

    We did Choral Shield last year but I think the program in Scavenger Hunt is simpler.

    Also, it looks like you have not had any more success than me at uploading stuff. I have emailed Charlie but as yet no reply/fix. Did you go for an auto detect screen width in the css files or two separate files? Also, what about the decipher button? What approach did you take there? At the moment, I think a Javascript solution looks the most appropriate for Higher.

    Ross Ritchie
    Participant

    Trying another upload, using Chrome this time. Used @media to detect resolution and Javascript for the button, the base html needs a little formatting to make it all work smoothly as well.

    Ross Ritchie
    Participant

    It finally uploaded, got a timeout error but it appears to be available for download

    David Muir
    Participant

    Thanks Ross. Looks like upload is working again, so I’ve just uploaded my Scavenger Hunt stuff. Comments etc. not just appreciated but eagerly sought!

    Just had a look at your solution. Not a lot to choose between our approaches to the different layouts for different devices but you have done a lot more work than me on the decipher button. The assessment specification says the button should “replace…” the cipher text and “display the decoded [sic] version…”. As far as I can see, pupils are not expected to actually write code to decipher the message. Given that they have already written a program to do that for the first part of the assessment, it would seem like overkill to make them do it again.

    What do others think? Do they need to decipher the message or can they just display an already deciphered version?

    chalove
    Keymaster

    Scavenger Hunt CSS code just needs a few additional rules to cover the different sizes. You can resize browser windows exactly for testing using http://resizemybrowser.com/ which will load a new browser window with the exact required size.

    I did this using JavaScript to do the SDD part but for the ISDD section I think you only need the layout and CSS. Given the complexity of designing responsive rules, I think the CSS and wireframe are sufficient for the ISDD marks (plus the HELP button which is a breeze as a JavaScript to write to the Dom on the page).


    @media screen and (max-width:999px)
    {
    #container { width: 800px; }

    #extras
    {
    clear: left;
    float: none;
    margin: 0 0 0 225px;
    width: 550px;
    }
    }

    @media screen and (max-width:480px)
    {
    #container { width: 400px; }

    #nav
    {
    float: none;
    width: auto;
    }

    #content
    {
    float: none;
    width: auto;
    margin: 0;
    }

    #extras
    {
    float: none;
    width: auto;
    margin: 0;
    }

    #feature-image { display: none; }
    }

    David Muir
    Participant

    Thanks Charlie

    The resizeMyBrowser site looks useful!

    I had problems with the tablet version at first and found I had to use:
    @media only screen and (max-width: 768px) and (min-width: 341px)

    I’m guessing it was an order thing since I had the mobile (i.e. narrower) definitions first, whereas you have the tablet definitions before the mobile version. (There was a good reason for choosing “768” and “340px” but I’m not sure now what it was!)

    Also, not entirely clear from your reply but looks like you are saying you did not decipher the message with javascript but just displayed some already deciphered text. Is that right?

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.