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 February 6.
This lab is worth a total of 80 points and contributes 8% toward the final grade.
Q1. Write a function to provide student's grade in letter (15 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 arguments: score in number
- Return the score in letter (A,B, or C)
Q2. Write a function to return the latitude and longitude coordinates for one of the 3 parks in Worcester: (15 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'
You output should like below:
Please use 'Elm' and 'White Rock' as example to show the results from your function
# 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. (20 pts)¶
You output should like below:
Q4. You need to create a function that show the list structure to store the names and letter grades of students taking an exam. (30 pts)¶
Write the function in a separate Python file named student_manager.py
Run the script (student_manager.py) using the Anaconda Prompt.
Test your script (student_manager.py) with four different inputs: 1, 2, 3, and a letter.
Provide a screenshot of your program, try four inputs: 1,2,3 and letter. You result should look like the screenshot below
The initial student list is as follows:
student = [['John',83.],['Katty',65.],['Tommy',85.]]
The program should provide the following options for the user:
- Option 1: When the user inputs 1, print the student list to the screen.
- Option 2: When the user inputs 2, prompt the user to input a student's name and grade, then append the new entry to the list.
- Option 3: When the user inputs 3, exit the while loop and terminate the program.
Error Handling:
- Use try | except | finally to handle potential errors.
- If the user enters a non-numeric value instead of 1, 2, or 3, catch the ValueError and display the message:
- "Please input a number to select the option"