Python代写:CSC108 Rent A Bike

Python基础应用作业,Toronto’s bike share network,练习List的使用。

Toronto bike share network

Introduction

This handout explains the problem you are to solve, and the tasks you need to complete for the assignment. Please read it carefully.

Goals of this Assignment

  • Develop code that uses loops, conditionals, and other earlier course concepts.
  • Practice with lists, including looping over lists, list methods, and list mutation.
  • Practice reading a problem description in English and provided docstring examples, and implementing function bodies to solve the problem.
  • Continue to use Python 3, Wing 101, provided starter code, a checker module, and other tools.

Rent-a-Bike

Toronto’s bike share network (https://en.wikipedia.org/wiki/Bike_Share_Toronto) debuted in 2011, offering rental bikes to Torontonians and visitors in the downtown core. This network consists of hundreds of docking stations scattered around downtown. Bikes can be rented from any docking station and returned to any docking station in the city. In this assignment, you will write several functions to help manage and track bike rentals across this network. Using real data from Toronto’s bike share system, your functions will simulate bike rentals and returns as well as keep track of the current state of the network and even provide directions to riders.

The data that you will work with is provided by the Toronto bike share network. The data contains information about the docking stations, such as the location of the station and how many bikes are currently available. More information about the data provided is given later in this handout.

The purpose of this assignment is to give you practice using the programming concepts that you have seen in the course so far, including (but not limited to) strings, lists and list methods, and loops.

This handout explains the problem you are to solve, and the tasks you need to complete for the assignment. Please read it carefully.

Files to Download

Please download the Assignment 2 Starter Files and extract the zip archive. A description of each of the files that we have provided is given in the paragraphs below:

Starter code: bikes.py

The bikes.py file contains some constants, and a couple of complete helper functions that you may use. You must not modify the provided helper functions.

The bikes.py file also contains function headers and docstrings for the A2 functions to which you are required to add function bodies. For each function, read the header and docstring (especially the examples) to learn what task the function performs. Doing so may help you to determine what you need to do for each required function. To gain a better understanding of each function, you may want to add more examples to the docstrings.

Data: stations.csv

The stations.csv file contains bike share data in comma-separated values (CSV) format. See below for detailed information on the file format. You must not modify this file.

Checker: a2_checker.py

We have provided a checker program (a2_checker.py) that tests two things: whether your functions have the correct parameter and return types, and whether your code follows the Python and CSC108 style guidelines.

The checker program does not test the correctness of your functions, so you must do that yourself.

The Data

For this assignment, you will use data from a Comma Separated Value (CSV) file named stations.csv . Each row of this file contains the following information about a single bike rental station:

  • station ID: the unique identification (ID) number of the station
  • name: the name of the station (not necessarily unique)
  • latitude: the latitude of the station location
  • longitude: the longitude of the station location
  • capacity: the total number of bike docks (empty or with bike) at the station
  • bikes available: the number of bikes currently available to rent at the station
  • docks available: the number of empty and working docks at the station

Note: While the sum of the number of bikes available at a station and the number of docks available at a station will usually equal the station’s capacity, this need not be the case. When a bike or a dock is broken, the sum of the two availability numbers will not match the capacity.

Another feature of a bike rental station is whether or not it has a kiosk. A kiosk allows a renter to pay for their bike rental using a credit card. Without a kiosk, renters can only pay for their bike through an app. Stations that are app-only (that is, that do not have a kiosk) have SMART somewhere in their name.

We have provided a function named csv_to_list , which reads a CSV file and returns its contents as a List[List[str]] . As you develop your program, you can use the csv_to_list function to produce a larger data set for testing your code. See the main block at the end of bikes.py for an example.

Your Tasks

Imagine that it is your job to manage Toronto’s bike share system. As the manager, you need to know everything about the system. But, there are hundreds of docking stations, which is way too many to keep track of in your head. To make your life easier, you will write Python functions to help you manage the system.

Your functions will fall into three categories: functions for data cleaning, functions for data queries, and functions for data modification.

Using Constants

As in Assignment 1, your code should make use of the provided constants for the indexes in your stations data. This will not only make your code easier to read, but if the columns in the data moved around, your code would still work.

Additional requirements

  • Do not add statements that call print, input, or open, or use an import statement.
  • Do not use any break or continue statements. We are imposing this restriction (and we have not even taught you these statements) because they are very easy to abuse, resulting in terrible code.
  • Do not modify or add to the import statements provided in the starter code.

Testing your Code

We strongly recommended that you test each function as you write it. As usual, follow the Function

Design Recipe (we’ve done the first couple of steps for you). Once you’ve implemented a function, run it on the examples in the docstring, as well as some other examples that you come up with yourself to convince yourself it works.

Here are a few tips:

  • Be careful that you test the right thing. Some functions return values; others modify the data in- place. Be clear on what the functions are doing before determining whether your tests work.
  • Can you think of any special cases for your functions? Test each function carefully.
  • Once you are happy with the behaviour of a function, move to the next function, implement it, and test it.

Remember to run the checker!

Marking

These are the aspects of your work that may be marked for A2:

  • Coding style (20%):
    • Make sure that you follow Python style guidelines that we have introduced and the Python coding conventions that we have been using throughout the semester. Although we don’t provide an exhaustive list of style rules, the checker tests for style are complete, so if your code passes the checker, then it will earn full marks for coding style with one exception: docstrings for any helper functions you add may be evaluated separately. For each occurrence of a PyTA error, one mark (out of 20) deduction will be applied. For example, if a C0301 (line-too-long) error occurs 3 times, then 3 marks will be deducted.
    • All functions you design and write on your own (helper functions), should have complete docstrings including preconditions when you think they are necessary.
  • Correctness (80%):
    • Your functions should perform as specified. Correctness, as measured by our tests, will count for the largest single portion of your marks. Once your assignment is submitted, we will run additional tests not provided in the checker. Passing the checker does not mean that your code will earn full marks for correctness.

How should you test whether your code works

First, run the checker and review ALL output you may need to scroll. Remember that the checker ONLY shows you style feedback, and that your functions take and return the correct types. Passing the checker does not tell you anything about the correctness of your code.

A2 Checker

We are providing a checker module (a2_checker.py) that tests two things:

  • whether your code follows the Python style guidelines, and
  • whether your functions are named correctly, have the correct number of parameters, and return the correct types.

To run the checker, open a2_checker.py and run it. Note: the checker file should be in the same directory as your bikes.py , as provided in the starter code zip file. When you run your own checker, be sure to scroll up to the top and read all messages.

If the checker passes for both style and types:

  • Your code follows the style guidelines.
  • Your function names, number of parameters, and return types match the assignment specification. This does not mean that your code works correctly in all situations. We will run a different set of tests on your code once you hand it in, so be sure to thoroughly test your code yourself before submitting.

If the checker fails, carefully read the message provided:

  • It may have failed because your code did not follow the style guidelines. Review the error description(s) and fix the code style. Please see the PyTA documentation for more information about errors.
  • It may have failed because:
    • you are missing one or more function,
    • one or more of your functions is misnamed,
    • one or more of your functions has the incorrect number or type of parameters, or
    • one of more of your function return types does not match the assignment specification, or
    • your .py file is misnamed or in the wrong place.

Read the error message to identify the problematic function, review the function specification in the handout, and fix your code.

Make sure the checker passes before submitting.

Running the checker program on Markus

In addition to running the checker program on your own computer, run the checker on MarkUs as well. You will be able to run the checker program on MarkUs once every 12 hours (note: we may have to revert to every 24 hours if MarkUs has any issues handling every 12 hours). This can help to identify issues such as uploading the incorrect file.

First, submit your work on MarkUs. Next, click on the “Automated Testing” tab and then click on “Run Tests”. Wait for a minute or so, then refresh the webpage. Once the tests have finished running, you’ll see results for the Style Checker and Type Checker components of the checker program (see both the Automated Testing tab and results files under the Submissions tab). Note that these are not actually marks – just the checker results. This is the same checker that we have provided to you in the starter code. If there are errors, edit your code, run the checker program again on your own machine to check that the problems are resolved, resubmit your assignment on MarkUs, and (if time permits) after the 24 hour period has elapsed, rerun the checker on MarkUs.

No Remark Requests

No remark requests will be accepted. A syntax error could result in a grade of 0 on the assignment.

Before the deadline, you are responsible for running your code and the checker program to identify and resolve any errors that will prevent our tests from running.