#506 · Python Basics · Beginner · Review the AI's code · 25 XP · about 3 min
Someone asked an AI assistant: "Write a function that returns the number of days in a month, given the month number and whether it is a leap year. If nobody says, assume it is not a leap year." This is its answer. It looks right, but it has a bug.
days_in_month(month, leap) should return how many days month number month has (1 is January, 12 is December). April, June, September and November have 30 days, February has 28, or 29 when leap is True, and the other months have 31. The leap argument is optional, and when it is left out the year is not a leap year.
days_in_month(1) # returns 31 days_in_month(4) # returns 30 days_in_month(2) # returns 28 days_in_month(2, True) # returns 29
First solves only, ranked by stars and then time.