Pair work Ch 2.5–2.6
- Due Feb 14, 2022 by 9:50am
- Points 1
- Available after Feb 14, 2022 at 9am
Problem 1
Consider the following except from the Python API documentation for the time module:
time.time()
→ float
Return the time in seconds since the epoch as a floating point number. The specific date of the epoch and the handling of leap seconds is platform dependent. On Windows and most Unix systems, the epoch is January 1, 1970, 00:00:00 (UTC) and leap seconds are not counted towards the time in seconds since the epoch. This is commonly referred to as Unix time.
(Fun side note, "epoch" is pronounced like "epic".)
Write a Python function with this signature: currentYear()
. It should use the time.time()
function to find the current date in seconds from Jan. 1, 1970 and produce the current year. You shouldn't need to look anything up as long as you know how many seconds are in a minute, how many minutes are in a day, and how many days are in a year.
Test your function by calling it and printing the result.
Problem 2
Create a function with the signature percentageToGradePoint(gradePercentage)
where gradePercentage
is a class grade on a 100-point scale (90-100 is an A, 80-89 is a B, etc.) and the function returns the grade point for that grade percentage. Here's the mapping:
Grade percentage | Grade point |
90-100 | 4 |
80-89 | 3 |
70-79 | 2 |
60-69 | 1 |
<60 | 0 |
You can perform this mapping using a one-liner and you may find the builtin max
and int
functions helpful (the latter will help you truncate fractional values). You can assume that no gradePercentage
above 100 will be entered.