I need to write a function called day_of_the_year
that takes a month and day as input and returns the associated day of the year. Let the month by a number from 1 (representing January) to 12 (representing December).
For example:
day_of_the_year(1, 1) = 1
day_of_the_year(2, 1) = 32
day_of_the_year(3, 1) = 60
Use a loop to add up the full number of days for all months before the one you're interested in, then add in the remaining days. For example, to find the day of the year for March 5, add up the first two entries in days_per_month to get the total number of days in January and February, then add in 5 more days.
So far, I have made a list:
days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
This is my code so far:
def day_of_the_year(month,day):
days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for number in day_of_the_year:
total = days_per_month[0] + days_per_month[1] + 5
return total
Is there something that I am missing?