Question: Step 6 (actually writing the day-of-year function): Write a function called day_of_year that takes three integer parameters: a month (1-12), a day (1-31), and a


Step 6 (actually writing the day-of-year function): Write a function called day_of_year that takes three integer parameters: a month (1-12), a day (1-31), and a year (any year is possible). This function should return the day of year (1-366) that this date occurs on. Here's how you do it. You need to two pieces of information: first, figure out whether the year is a leap year or not (hint---call your is_leap function on the year and capture the return value). Next, get the appropriate magic_month value for the month (hint---call your magic_month function on the month and capture the return value). The formula for finding the day of the year is quite simple: The day of the year is the magic_month number plus the day of the month. If this year is a leap year and the month is March or later, add one to this result. The definition line of this function should look like this def day_of year(month, day, year): Example: Suppose we call day of year(7, 29, 2019) to calculate the day of the year for July 29, 2019. 2019 is not a leap year, and the magic_month number for July (month #7) is 181. So the day of the year here is 181 +29, which is 210. Example 2: Suppose we call day_of_year(4, 11, 2016) to calculate the day of the year for April 11, 2016. 2016 is a leap year, and the magic_month number for April (month #4) is 90. So the day of the year here is 90 + 11 + 1, which is 102. Step 6A: Test your day_of_year function. In [8]: #This imports all the functions in your file so that they can be used in the notebook. from pcalendar import * print(day_of_year(7, 29, 2019)) #should print 210 print(day_of_year(4, 11, 2016)) #should print 102 print(day_of_year(12, 31, 2100)) #should print 365 def is_leap (year): if year % 4 == 0 and year % 100 != 0: 1900 not being leap years return (True) elif year % 100 == 0 and year % 400 == 0: return (True) else: return (False) def magic_month(month): #return the given value if month == 1: #1= January, 2= Feburary return 0 if month == 2: return 31 if month == 3: return 59 if month == 4: return 90 if month == 5: return 120 if month == 6: return 151 if month == 7: return 181 if month == 8: return 212 if month == 9: return 243 if month == 10: return 273 if month == 11: return 304 else: #have to have an else stateme return 334
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
