Skip to content

EECS1015-F20 Lab5

  • If you are using PythonCode for the first time, first watch the introductory Video for Simple mode at youtube.
  • In your browser, go to the URL: https://pythoncode.eecs.yorku.ca. Login with Your Passport York or EECS Credentials.
  • It is best to obtain EECS credentials (login/password). The process is simple at https://webapp.eecs.yorku.ca/activ8/. You will need your student number. PythonCode allows you to self-grade your work with Unit Tests, but to submit your work easily, obtain and EECS account.

Video for Lab5

Video for Lab5. This video walks you through the steps described below. Watch video in HD (1080p).

Small Change from the original specification:

In the README file on PythonCode for Lab5:

We have added one extra function getNameDict(nameDict, cities) not in the original specification of the instructor. This function returns a string representation of nameDict for a list of cities. You can then implement function printNameDict using getNameDict.

def printNameDict(nameDict, cities):
    print(getNameDict(nameDict, cities))

The function printNameDict() returns nothing, and prints to the console; thus, it cannot be directly checked by a unit test. Hence, the getNameDict() function serves as a helper function for printNameDict(), so that getNameDict() stores and returns the output as a string. And printNameDict() calls printNameDict() and print out the returned string. In this way, we are able to test the output by comparing the returned string of getNameDict(). Some of the unit tests check the correctness of getNameDict(). The final output should be the same as the original instructor specification.

More on Unit testing.

Login to PythonCode

To get started, login to PythonCode (with your EECS credentials, if you want to submit from it as well).

Switch to Tutorial mode

For Lab5, select Switch mode in the dropdown menu as follows:
switch

Retrieve Lab5 starter code

Then select the Tutorial mode, category labs and item Lab5:

select

Examine starter code from instructor and implement

This will set you up with skeleton code with empty functions consistent with the official description at https://trinket.io/python/f24922d729.

select

  • The starting code is in lab.py. This is also the main file that must be submitted for grading. The function bodies are empty and you must implement them so that the unit tests pass.
  • The unit tests are in test_lab5.py. Start by getting the first unit test test_fromCity_Toronto() to work. This test checks the function fromCity in lab.py. The assert keyword is followed by a boolean predicate that evaluates to True or False, i.e. an assertion expresses a logical proposition using the variables and the functions of a program that always should evaluate to true at that point in code execution. Assertions can help a programmer read the code, and detect defects. Here is the first test.
def test_fromCity_Toronto():
    expected = ["Richard", "Jia-Tao"]
    actual = lab5.fromCity(lab5.testDict, "Toronto")
    assert expected == actual

If you implement the function `fromCity() correctly, and press the Grade button, you should see the first test (and some other tests) showing as green.

select

You are still getting a red bar at the top because at least one test (or more) is still failing. Your grade so far is 25/105.

Keep implementing each function in the starter code until you get a Green bar at the top.

select

Save your work regularly

Note

Whenever you switch modes or projects, your work will get lost. Either Export your code to your local disk to save it (as a zip file). Or you can Store your code (for later retrieval) as shown below this note:

select

If you Store your work in PythonCode, you can always Retrieve it at any time.

select

Submit your work for grading

Note

The name of your project must be Lab5.

select

Hit the Submit button and you should then see the following:

select

Keep submitting as many times as submission is open. It is your last submission that will be graded by the instuctor.