Python 代写 |计算机代写


UCL COMP0015 Introduction to Programming

Coursework Vampire Hunting


This document explains the arrangements for the coursework. You will create an application that analyses a dataset to determine how a vampire infiltration spreads based on testing and contact tracing data. This document is fairly lengthy; do not be deterred by this. The coursework has been carefully designed so that you can complete it part by part and know that you have the correct functionality at each point. Each part is described in its own section.


How to submit your work

Submit your contact.py file at the assignment link on Moodle. Do not submit any other files. Do not upload a folder containing your files because this can cause compatibility issues for the marking team. You must ensure that your program works properly on your own computer before you submit the code.

Important: make sure your student number (not your name) is included in the comments at the top of your program. Testing

You are responsible for testing your program carefully. Make sure that you have thought about all the things that can go wrong and test your program to ensure that you know it works correctly in all circumstances.

However, as an aid, we have developed a web-based testing service. We strongly encourage you to take advantage of this service. More details can be found in Appendix 1, the following points are key:

1. The tool may be extremely helpful—in previous terms, students in aggregate used the service 5,000+ times.

2. Nevertheless, the tool does not provide any guarantee of a final grade.

a. Your final submission will be tested on additional datasets, which can change scores.

b. Your final grade will include marks for comments/style, which can change scores.

c. We reserve the right to modify your grade after manual inspection. For example, attempts to “trick”

the autograder will result in zero marks.

d. If your code does not work with the autograder, we may attempt to modify it to award a non-zero

grade. If successful, we will deduct some marks (typically 10-20%, although we make no guarantees). Accordingly, please make sure your code works properly with the autograder before submitting.

3. We do not guarantee that the testing service will always be available (e.g., the server may crash).

4. The testing service tests each part individually. If you get stuck on one section but can get something working for a later section, then you may still be able to get marks for that later section, even if running it on your own machine (which will use the pre-defined main() function from the template) doesn’t work.

5. The testing service can sometimes get confused by non-ASCII characters. Accordingly, and with apologies, avoid using Amharic/Arabic/Chinese/Thai/etc. characters in your code, even within comments.

Assessment

You are expected to show that you can code competently using the programming concepts covered in the course including (but not limited to): the use of files, strings, lists, dictionaries, sets, conditions, loops, and functions.

Marking criteria will include:

● Correctness – your code must perform as specified.

● You must apply Python concepts appropriately.

● Programming style – see section ‘Appendix 2 Style Guide’ for more detail.

● Your assignment will be marked using the rubric in Appendix 3. This is the standard rubric used in the

Department of Computer Science. Marks for your project work will be awarded for the capabilities (i.e. functional requirements) your system achieves, and the quality of the code. Categories 5 and 6 of the rubric will be used for coding assignments.

Before starting your assignment

You are provided with some starter code in the file template.py. Your first action should be to make a copy of this code into a new file, contact.py, where you will work afterwards. You have also been given a helper file format_list.py; you shouldn’t modify this but will need to have it in the same directory. You have also been given some text input files containing infiltration data (DataSet0.txt ... DataSet5.txt) and associated text output files (DataSet0-out.txt ... DataSet5-out.txt). You should put these in the same directory also.

Before you start writing code, read through this entire document so that you have a sense of what’s coming and can start to think about how different parts are going to work together. The overall task is more complex than anything you’ve done so far, but it’s also been broken into—forgive me—bite-sized pieces. In section 22, there is a summary of all of the different functions you have to write, the number of lines in the official solution (just to give yourself a sense of relatively difficulty—your own solution might be quite a bit longer, and that’s ok), and an informal sense of which parts are a bit trickier than others (sometimes short functions can be trickier than long ones).

Keep in mind that the testing service you have access to (see appendix 1) and the way we will do the grading will be function-by-function. So, even if you can’t get some critical function working correctly, work on other functions.


Running the contact tracing program

There are two ways to run the program from the terminal depending on whether you want to provide the data file name on the command line or whether you want the user to be prompted for the file name. The code in main() contains code to handle this. Important: you should not edit the code in main().

Entering a file name on the command line (suggested)

On Windows, run the program in the terminal, specifying the data file name:

Section 1: Orientation

You have been given several files containing testing and contact tracing data for vampire infiltrations. This data has a “preamble” (initial part), followed by a list of testing and contact tracing data for a series of days (“body”). The format will be explained in detail below.

In order to work with the contact tracing data, you will need to load a data file storing contact tracing data and create appropriate data structures such as a dictionary or a list. These data structures can be used to identify the relationship between the individuals in the data.

Many of the sections require you to print out data after you have calculated it, often in separately-specified functions. Sometimes functions will require you to check for some kinds of data errors, print specified error messages, and then exit by calling sys.exit().

Important: do not modify the main() function; all of your work should be in the other functions as specified in the various sections. Do not add code that just runs at the “top level”. All of your code should be inside functions.

Important: Part of our testing procedure is to run functions individually. Make sure that your function names, parameters, and return values don’t change from our specification. Moreover, make sure that your functions do what they are supposed to do, rather than e.g., trying to do one big function that does the job of several of our specified functions.

Important: Ensure that your program’s output matches exactly the output given to you unless otherwise specified. Important: do not import any additional packages; lines 7-9 of the template.py file already imports sys, os.path,

and format_list; that’s all you need (and all you are allowed). Data files


The files (as well as your assignment’s expected output for each file) are posted on moodle with the assignment information. Each file ends with the .txt extension. You can open the files in Visual Studio Code or in a text editor to see the contents.

 

The python interpreter. On macos this will be python3 and on Windows, this will be py or python.

contact.py

The name of the python program.

DataSet0.txt

Name of the data file.

The preamble begins with a (comma-separated) list of individuals (without specifying which are humans and which are vampires). These are all of the individuals that may appear in the rest of the dataset. On the next line, the preamble gives the number of days of data that will follow. For example, a valid preamble would be as follows:

Bella, Edward, Jacob, Carlisle, Alice, Emmett, Charlie, Renee, Jessica, Angela


N.B. Sometimes spaces are included around names to aid human readability as in the above example; these are optional, but your code will have to remove them if they appear. The strip() method can help you do this.

Important: names may include a mixture of upper and lowercase letters, as well as some special characters such as dashes. 

Unlike in some of the legends, our vampires are able to move around during the day, rather than sleeping in coffins. (Some of them do sleep in coffins at night, but that’s not important for this exercise.) We divide each of our days into two parts (AM, when testing occurs; and PM, when contact occurs). Each day has the following format. On the first line is a comma-separated list of people who have been given a vampirism test in the morning (AM) of that day (perhaps a brief exposure to sunlight); the result of the test (“V” for vampire or “H” for human) is given after each name, separated by a colon. If no one is given a test on a given day, this line will be the special string ##.

On the second line is a number of groups of people who had interactions in the afternoon (PM) of that day. On the third and following lines are comma-separated lists of individuals who have been in contact. To keep things simple:

1. Each individual can be in at most one contact group on a given day.

2. On the other hand, there’s no need for an individual to meet with anyone on a given day; in that case, their name won’t appear in any contact list for that day. When vampires are in the neighbourhood, staying home alone can be the safest option!

3. All people in a group meet simultaneously (perhaps to play a game of baseball).

Here’s an example of a valid day:

Edward : V, Bella : H, Jacob : H, Jessica : H 3

Bella, Edward

Charlie, Jacob

Alice, Renee

N.B. Again, spaces can appear to aid human readability; in this case you’ll have to remove them.

To complete the demonstration of the input, here are the remaining three days promised in the preamble above:

   Bella : H, Jacob:H, Alice :V, Charlie: H 2

Bella, Edward, Charlie

Angela, Jessica

Emmett : V, Renee : H, Jessica : V 0

Bella : V, Charlie: H

Bella, Edward, Charlie, Jessica, Angela Jacob, Renee

Notice that on the third day everyone stayed home (0 contract groups). None of the days had zero tests (which we would have indicated with ##).


Section 2:
Take a look at the following code in main():

The python code sys.exit() will cause the program to terminate if the file cannot be opened and read. Important: do not change the code in main().

The function file_exists() takes the file name given as a parameter, and checks that the file exists. Your first task is to complete the function file_exists(). The function file_exists()must return True if the file exists and False if it does not. Hint: use the function isfile() from the python library os.path.

Section 3:
Within each list-pair, the first element should be a dictionary whose keys are the names of those tested for vampirism and whose values are the Booleans True (that is, a vampire, indicated by “V” in the input file) or False (that is, a human). The second element of a list-pair is a list of lists, with each “outer” list-element being an “inner” list of those groups who were in contact on that day. After you finish processing the file, make sure to close it, and then return the structure you’ve created. Here’s the structure we’d expect for the sample file given above, as printed by Python:

(['Bella', 'Edward', 'Jacob', 'Carlisle', 'Alice', 'Emmett', 'Charlie', 'Renee', 'Jessica', 'Angela'], [({'Edward': True, 'Bella': False, 'Jacob': False, 'Jessica': False}, [['Bella', 'Edward'], ['Charlie', 'Jacob'], ['Alice', 'Renee']]), ({'Bella': False, 'Jacob': False, 'Alice': True, 'Charlie': False}, [['Bella', 'Edward', 'Charlie'], ['Angela', 'Jessica']]), ({'Emmett': True, 'Renee': False, 'Jessica': True}, []), ({'Bella': True, 'Charlie': False}, [['Bella', 'Edward', 'Charlie', 'Jessica', 'Angela'], ['Jacob',

'Renee']])])

If the file isn’t somehow formatted correctly – for example, if one of the numbers isn’t a number when you convert it to an integer – then print the error message

Error found in file, aborting. Then, exit (using sys.exit()).

Important: for this section, and all sections that follow, you should print to the screen (rather than, e.g., writing your results to a file). Also, it is critical that you produce the exact error message we specify to get the mark.


咨询 Alpha 小助手,获取更多课业帮助