Lab 02
Lab 02: Python Fundamental Part 02
This lab covers the fundamentals of Python data, including topics such as loop, while and functions.
There are three questions in total. Please provide your code answers directly below each question.
Make sure to run all cells so that the answers are stored. Once completed, export your .ipynb file as either HTML or PDF, ensuring that all answers are included. Submit the HTML or PDF file to Canvas by midnight (11:29 PM) on Feb 12.
This lab is worth a total of 50 points.
Q1. Write a function to provide student's grade in letter (10 pts)¶
If student's score range from 100 - 80 then return A, range from 79-60 then return B, below 60 then return C
The function should:
- Take one input: score in number
- Return the score in letter (A,B, or C)
Please use 90, 75, and 50 to test your function. Your results should match the output shown in the image below.
Output
Q2. Write a function to return the latitude and longitude coordinates for one of the 3 parks in Worcester: (10 pts)¶
- Take one arguments: park name
- Return the latitude and longitude of the park
- If input argument is not in the dictionary, return 'Park not found'
More information about in and not in (Python membership operator) in this link (https://www.w3schools.com/python/python_operators_membership.asp)
Please use Elm, White Rock test your function. Your results should match the output shown in the image below.
Output
Input
# Use below dictionary to finish Q2
parks = {
'Elm':"42.269, -71.815",
'Wetherell':"42.273, -71.823",
'Institude':"42.277, -71.803"
}
Q3. Write a function to check whether a given latitude is valid (between -90 and 90 degrees). If the input is not a number, it will catch the error and handle it. The output from the function should be a sentence describing the result to users. (10 pts)¶
Please use 45, 120 test your function.
You output should like below:
Q4: Write a function to read a simple dictionary and build a new, more complex dictionary (a dictionary of lists) based on conditional logic. (20 points)¶
Problem: Write a function named group_cities_by_size that accepts a dictionary of city populations. It should return a new dictionary with three fixed keys: Small, Medium, and Large. The values for these keys should be lists of city names falling into the criteria:
Small: Population < 50,000
Medium: Population between 50,000 and 100,000 (inclusive)
Large: Population > 100,000
Input test data
# Test Data
cities_input = {
'Conway': 64000,
'Little Rock': 202000,
'Vilonia': 4000,
'Fort Smith': 89000,
'Dallas': 1300000,
'Mayflower': 2000
}
output