Description
Important reminder
- You must submit your lab via web-submit. You can try this using our new platform! See details at the end of the lab description.
- Please make sure you correctly submit your file (only a single file please – py).
- Please follow the instructions carefully – read the lab carefully to understand everything you need to do. This lab requires you to implement multiple functions. Each function uses or processes lists, dictionaries, and tuples.
- GOALS/OUTCOMES FOR LAB
- To practice using lists, dictionaries, and tuples
- To use for-loops with lists, dictionaries, and tuples
- To continue using functions and control-statements
- LAB 5 – TASK/INSTRUCTIONS
Task 0: [This will be the same for all labs]: Start your code with comments that include this lab ID, your full name, email address, and student id as follows:
# Lab 5
# Author:
# Email:
This lab involves you generating several functions. Please read carefully. A video of this lab running is available here.
https://www.eecs.yorku.ca/~mbrown/EECS1015_Lab5.mp4
- NEW – Testing Platform with Submit!!!!
We are researching a new EECS platform, PythonCode, for students to write, test, auto-grade, and submit their labs.
This is not part of EECS1015, however, if you would like to try it out, please go to the following link:
https://www.eecs.yorku.ca/~stateclock/python/lab5/
If you have problems with the PythonCode, please email: Mr. Shangru Li [email protected]
See explanation of the lab on next page.
Lab 5 – Manipulate data involving user names and cities
STARTING CODE LINKS
This lab starts with skeleton code that you can find here: https://trinket.io/python/f24922d729 Or on the self-grading platform here: https://www.eecs.yorku.ca/~stateclock/python/lab5/
The starting code defines global variables bound to tuples and a dictionary as follows:
names = (“Masha”, “Kevin”, “Ruigang”, “Vlad”, “Ramesh”, \
“Aditi”, “Caroline”, “Panos”, “Chuck”, “Grani”, \ “Rutha”, “Stan”, “Qiong”, “Alexi”, “Carlos”) cities = (“Toronto”, “Ottawa”, “Hamilton”) testDict = {“Richard”:”Toronto”, “Jia-Tao”:”Toronto”, “Justin”:”Ottawa”, “Lars”:”Ottawa”}
You need to define and implement the following functions:
getRandomItem(parameter: a list or tuple) -> returns an item from the list or tuple
This function will randomly select an item from the list or tuple passed as an argument.
For example, if you call getRandomItem(names), then it would return one of the items from the tuple names.
createNameDictionary(parameters: none) -> returns a dictionary
This function will create a new dictionary.
This function uses the global variables: names and cities (shown above)
This function returns a dictionary where each name in the names tuple is a key in the dictionary.
The key’s value is randomly selected from he cities tuple using the getRandomItem() function.
Essentially the function creates a dictionary of names, where each name is randomly assigned to a city.
Your function will return this dictionary.
fromCity(parameters: dictionary, string) -> returns a list
This function takes a dictionary and a string with a city name.
The function will return a list of all the names in the dictionary who are from that specified city.
For example: fromCity(testDict, “Toronto”) would return a list [‘Richard’, ‘Jia-Tao’] removePeopleFrom(parameters: dictionary, string) -> no return, but modifies dictionary
This function takes a dictionary and a string. The string is a city name.
This function will delete all items in the dictionary whose value is equal to the string.
For example: removePeopleFrom(testDict, “Toronto) would modify the testDict to be {“Justin”:”Ottawa”, “Lars”:”Ottawa”}
printNameDict(parameters: dictionary, tuple of strings) -> nothing
This function takes a dictionary and a tuple of strings. The tuple items are the city names.
This function will loop through the tuple of cities and print out the name of the people who live in that city.
The peoples names will be numbered. For example: printNameDict(testDict, (“Toronto”, “Ottawa”)) prints: People from Toronto:
- Richard
- Jia-Tao
People from Ottawa:
- Justin
- Lars
continue on next page
If the dictionary does not have a person from a city, it should print *None*
For example, printNameDict(testDict, (“Toronto”, “Ottawa”, “Hamilton”)) prints: People from Toronto:
- Richard
- Jia-Tao
People from Ottawa:
- Justin
- Lars
People from Hamilton *None*
main(parameters: none) -> no return
Your main function will be used to test the functionality above.
Main will have two parts. Part 1 will be used to test the functions one by one (except createNameDictionary), using the testDict variable.
Part 2 will apply the function to a larger dictionary created by your function createNameDictionary(). Ideally, if you can get part 1 to work properly, part 2 will work as long as your createNamedDictionary() function is correct.
Main part 1 works as follows:
- Test the getRandomItem() function with argument global variable: cities
- Test the fromCity() function with arguments testDict and “Toronto”, then testDict and “Ottawa”
- Test printNameDict() function with arguments testDict and tuple (“Toronto”, “Ottawa”)
- Test removePeopleFrom() function with arguments testDict and “Ottawa” To verify, call printNameDict() again
Main part 2 works as follows:
- create a new dictionary using the createNameDictionary() function
- call printNameDict with this new dictionary and the cities tuple (3) For each city (Toronto, Ottawa, and Hamilton) call the fromCity() function and print the returned lists
(4) Use the removePeopleFrom() function to remove all the people from Hamilton and Toronto from the dictionary (5) call printNameDict to show the people have been removed
See next page for an example output of Lab 5.
EXAMPLE OUTPUT OF LAB 5
Part 1 – Testing functions with `testDict’
Testing getRandomItem() function (‘Toronto’, ‘Ottawa’, ‘Hamilton’) item = Toronto Testing fromCity() function
[‘Richard’, ‘Jia-Tao’]
[‘Justin’, ‘Lars’]
Testing printNameDict() function
People from Toronto:
- Richard
- Jia-Tao People from Ottawa:
- Justin
- Lars
Testing removePeopleFrom() function
People from Toronto:
- Richard
- Jia-Tao People from Ottawa: *None*
Part 1
- Test the getRandomItem() function with argument global variable: cities
- Test the fromCity() function with arguments testDict and “Toronto”, then testDict and “Ottawa”
- Test printNameDict() function with arguments testDict and tuple (“Toronto”, “Ottawa”)
- Test removePeopleFrom() function with arguments testDict and “Ottawa”
– To verify, call printNameDict() again
- Panos 2. Grani
- Alexi People from Ottawa:
- Masha
- Kevin 3. Vlad
- Aditi
- Caroline
- Stan People from Hamilton:
- Ruigang
- Ramesh
- Chuck 4. Rutha
- Qiong
- Carlos Toronto List:
[‘Panos’, ‘Grani’, ‘Alexi’] Hamilton List:
Ottawa List:
*None* People from Ottawa:
- Masha
- Kevin
- Stan People from Hamilton: *None*
- GRADING SCHEME
This lab is more challenging than lab 3 and 4. However, the notes and trinkets examples are all-sufficient to help you do this lab. To get full marks you need to make sure you follow the instructions correctly. The following will be our grading scheme for the Lab components specified in Section 2 of this document.
Task 0:
- Filename must be “py” (all lowercase, no spaces)
- The Python comments at the beginning of your program must include your name, email, and York student id (this is important for grading)
- If your file name is incorrect, your or do not put in the required information we will deduct -5 points (Why are we so harsh? Because if you don’t put in your name and student id it can be very difficult for the TAs to determine whose submission this is.) Main Task :
- 5 functions [-2 points for each that doesn’t work properly] main function [-2 if the main doesn’t work] You can’t receive below a 0.
-No submission – 0 points
-Any submission 1 week after the due date 50% off the total marks
-Any submission 2 weeks after the due date will not be marked and treated as no submission.
See pages below on how to submit your lab code.
MAKE SURE TO SELECT Lab5 with websubmit
Note, if you use the new experimental testing platform it can perform websubmit for you!



