Questions/answers about ACOM1900 Coursework 1

Q: What format are the times in the csv provided in? Are they seconds or mm:ss? A: Seconds.

Q: the first line of the example results file contains column headers, but the format specification doesn't mention whether this will always be the case. Can I expect the first line of the file to always contain the table headers? Also, should I expect the columns to always be in the same order? I know we haven't gotten to exception handling yet, but should I do some basic error-checking for any of these things? A: The format will be identical to the example results file. I.e., the first line will contain table headers, and the columns will be in the same order. In addition, there will not be any empty fields. You don't have to do error checking for ant those things..

Q: I am not sure which file the program should read from as two are mentioned in the write up. It says to run form a .csv file and the example is of this type but it says later on to use cw1-results.txt. Which file should i use in the code? A: Oops! Use either cw1-results.csv or cw1-results.txt (I'll make sure there are two copies of the file.

Q: The coursework says that the results will be provided to me in a text file, so how do I import or input(I don't know what to do)a text file into python? A: See slide 8 of the Data Types lecture, and related material in the text book (e.g., p175 of Python Power).

Q: There have been a few enquiries about what should be output. A: As the coursework specification indicates, you only need to output the name and total time for each team, in the order they came. As is the norm in athletics, the time should be output in the form "hh:mm:ss" (hours:minutes:seconds).

Q: Establishing variables for each team. How do we go about getting python to create a variable for each team name? If we knew before hand what teams were entering we could establish variable such as .TEAM A = 0. to start the count for each team. What command instructs python to invent variables as it comes across new team? A: The key to this is to use a data structure like a list (NB: dictionaries are, in effect, a special type of list). In python it's possible to create an So team names/times could, for example, be stored in two separate lists (you have to keep them synchronised) or as pairs of values stored in a list (as suggested in the last lecture). Try out lists on some simple examples to get used to how they work.

Q: Basically I've created a dictionary which is showing the teams and their values added up, howewver except for team B all the adding up is wrong and I'm not sure why? I've attached what I've done really can't spot the mistake! A: Ah yes, you've found one of the most important skills any software developer needs to learn. We all find problems like this, where we simply can't understand why our programme isn't working, even (as in your case) when there are only a few lines of code. What you need to do is to localise the problem, to find just one or two lines of code that are the cause. One of the best ways of doing that is to interrogate the value of particular variables, either in a debugger or by printing out disgnostics. In your case, I think you'll find the programme is doing though one of your 'for' loops many times more than you expect, so the value you calculate is different to the one you thought you would! Try putting in some extra print statements, to see how many times your programme goes through the for loops, what gets changed within a loop and the value it gets changed to. If that makes you scream 'HOW STUPID!!!!!!' then make sure you also smile because we all do things like that and it really is one of the best ways of learning from one's experience :-)

Q: When I make an error using idle python shell, I cannot correct it, so I have to start all over again. Is there anyway I can rectify this? A: I presume you're typing python commands directly into the shell. If you create a python file (file -> new -. etc.) you can then edit and run it within IDLE.

Q: ... I really can't for the LIFE of me, figure out how to call upon the data in the dictionary in order to first add the team times, then display them in the correct order ...

import csv
reader = csv.DictReader(open("cw1-results.csv"))

A: Read the documentation carfully to understand what functions like DictReader() do (rather than half guessing). If you add the following lines after your code you'll see that each row of the file is being read as a dictionary, and knowing that you can access the data by using 'TIME' etc. as a key.

for row in reader:
---print row

Q: I have written the code to read in a file, display only certain parts of the strings, and print only the teamname and the time. But i've just got one problem. What kind of code would i use to send specific times to specific lists. Basically an empty list will be created for each team and i want to be able to pick out for example for team A, i want the list to collect data for all the legs from team A. A: You can either use 2 lists (one stores the team name and the other adds the time for the teams), making sure that position N corresponds to the same team in both lists. Or alternatively use a dictionary to store name and cumulative time in one data structure.

Keep the questions coming!