From the course: Learning Python

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Dates and times

Solution: Dates and times - Python Tutorial

From the course: Learning Python

Solution: Dates and times

- [Host] All right, so how'd you do on this one? The key to solving this challenge was to use the month calendar class that is in the calendar module, which is what I listed in the hint section of the challenge instructions. So let's go over my code. Remember that our function is given a year and a month along with a weekday value from zero to six which represents a day of the week, with zero being Monday and six being a Sunday. And our task was to return the number of those days that appear in the given month. So the number of Mondays, the number of Tuesdays, so on. So my code imports the calendar module and sets the day count to zero. And then I use the month calendar method to get the month for the given year. Now this function returns an array of lists for the specified month, and each list in the array represents a week that's in that month. Each one of those week lists contains seven integers and each index into that…

Contents