CSC108H Assignment 2: Bike-Share
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CSC108H Assignment 2: Bike-Share
Due Date: Thursday, March 17, 2022 before 5:00pm
This assignment must be completed alone (no partners). Please see the syllabus for information about academic offenses.
Late policy: There are penalties for submitting the assignment after the due date. These penalties depend on how late your submission is. Please see the Syllabus for more information.
Goals of this Assignment
Develop code that uses loops, conditionals, and other earlier course concepts.
Practice with lists, including looping over lists, using list methods, and list mutation.
Practice reading problem descriptions written in English, together with provided docstring
examples, and implementing function bodies to solve the problems.
Continue to use Python 3, Wing 101, provided starter code, a checker module, and other tools.
Bike-Share
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.
The problems that you are to solve and the tasks you need to complete for the assignment are explained in this handout. Please read it carefully.
Files to Download
Please click here (https://q.utoronto.ca/courses/249645/files/19668675/download?download_frd=1) to download the Assignment 2 Starter Files and then extract the files in the zip archive. A description of each of the files that we have provided is given in the paragraphs below:
Starter code: bike_share.py
The bike_share.py file contains some constants, and a couple of complete helper functions that you may use. You must not modify the provided constants or helper functions.
The bike_share.py file also contains function headers and docstrings for the Assignment 2 functions for 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, in the order listed:
station ID: the unique identification (ID) number of the station
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 rental through an app. Stations that are app-only (that is, that do not have a kiosk) have the string 'SMART' somewhere in their station name. (The bike share system could later change 'SMART' to some other phrase, so, when coding, use the constant NO_KIOSK that we provide instead of the string 'SMART' .)
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 bike_share.py for example usage.
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.
The functions that you complete will fall into three categories: a function for data conversion, functions for data queries, and functions for data modification.
Data conversion
As mentioned earlier, we have provided a function named csv_to_list that reads data from a CSV file and returns it in a List[List[str]] . Here is an example of the type of list returned by
csv_to_list :
Notice that all of the data in the inner lists are represented as strings. You are to write the function convert_data , which should make modifications to the inner lists according to the following rules:
If and only if a string represents a whole number (ex: '3' or '3.0' ), convert the string to an
int .
If and only if a string represents a number that is not a whole number (ex: '3.14' ), convert the
string to a float .
Otherwise, leave the string as a str .
After applying the convert_data function to the example list, it should look like this:
Before you write the body of the convert_data function, please note:
you must not use the Python built-in function eval , and
this function is one of the more challenging functions in Assignment 2, because it mutates a list.
We suggest that you start with some of the other functions, and come back to this one later.
2022-03-18