Use the command line to create a new directory called lab9 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.
Grade Conversion
Create a Python function called convert_to_letter_grade
in a file called grades.py
. The function should take a numeric grade from 0 to 100 and print the associated letter grade using the following scale:
A = [90, 100]
B = [80, 90)
C = [70, 80)
D = [60, 70)
F = [0, 60)
Note that a square bracket means inclusive and a parenthesis means exclusive. Be sure to test your program on the boundaries of the ranges.
Leap Year
Create a function called is_leap_year(year)
in a file called date.py. The function should return True
if the specified year is a leap year, False
otherwise. A leap year occurs almost every 4 years. All leap years are divisible by 4, but not all years that are divisible by 4 are leap years. Years that are divisible by 100, but not divisible by 400 are not leap years.
Days in Month
Create a function called get_days_in_month(month, year)
in the date.py file. The function should return the number of days in the specified month. Months are specified as integers between 1 and 12. Use the is_leap_year
function to help compute the number of days when the month is February. Also use elif
s and think carefully about the order, so that the number of conditional statements is kept to a minimum.
Valid Date
Create a function called is_date_valid(day, month, year)
in the date.py file. The function should return True
if the specified date is an actual day in the Gregorian calendar, False
otherwise. The function’s parameters should specify a date as three integers. Use the get_days_in_month
function to help determine if the day input is valid.
Submission
Please show your source code and run your test cases for the instructor or lab assistant. Only a program that has perfect style, thorough test cases, and flawless functionality will be accepted as complete.