From the course: Python Code Challenges for Object-Oriented Programming

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: First and last day

Solution: First and last day

- [Instructor] All right, let's take a look at this challenge. Now, we have two test cases here. So in the first test case, if I provide the Feb, 2030, 2 month object and I want to get the first day, I should return a datetime.date object, which has 2030, Feb, and that's the first of Feb. And similarly, in the second test case, if I have the Feb of 2030 and I want to determine what the last day is, it'll return that the last day is going to be the 28th. So if I go ahead and select Test my code, you can see that I've got an attributeError. The 'Month' object has no attribute 'first_day' and that's because we haven't entered any code in yet. Now, calculating the first day of a month is trivial as it's always going to be one, but it's not as simple to calculate the last day of a given month. So let's go ahead and take a look at monthrange. So I'm going to go ahead and import calendar, (keyboard clacking) and I want to just take a look at monthrange. So I'm going to go and print out the…

Contents