If you are not allowed to use a library, you can use this shorter one:
def next_date(d, m, y):
days = [31,28,31,30,31,30,31,31,30,31,30,31]
if is_leap_year(y):
days[1] = 29
if d < 1 or d > days[m-1] or m < 1 or m > 12:
return "No such date exist"
d += 1
if d > days[m-1]:
d, m = 1, m+1
if m > 12:
d, m, y = 1, 1, y+1
return (d,m,y)
You can test using the following:
print next_date(10, 2, 2014)
print next_date(28, 2, 2014)
print next_date(29, 2, 2014)
print next_date(31, 12, 2014)
Also, here is a simple implementation for is_leap_year
which you did not implement:
def is_leap_year(y):
return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)