Skip to content

Commit 14dc01e

Browse files
committed
finds next date for a given date
1 parent a0e8216 commit 14dc01e

File tree

1 file changed

+49
-0
lines changed
  • Udacity Data Structure and Algorithms Nanodegree/Introduction

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
###
2+
### Define a simple nextDay procedure, that assumes
3+
### every month has 30 days.
4+
###
5+
### For example:
6+
### nextDay(1999, 12, 30) => (2000, 1, 1)
7+
### nextDay(2013, 1, 30) => (2013, 2, 1)
8+
### nextDay(2012, 12, 30) => (2013, 1, 1) (even though December really has 31 days)
9+
###
10+
11+
12+
def next_day2(year, month, day):
13+
"""Simple version: assume every month has 30 days"""
14+
if day < 30:
15+
return year, month, day + 1
16+
else:
17+
if month == 12:
18+
return year + 1, 1, 1
19+
else:
20+
return year, month + 1, 1
21+
22+
23+
def next_day(year, month, day):
24+
"""
25+
Returns the year, month, day of the next day.
26+
Simple version: assume every month has 30 days.
27+
"""
28+
# YOUR CODE HERE
29+
if month == 12:
30+
if day == 30:
31+
day = 1
32+
year += 1
33+
month = 1
34+
else:
35+
day += 1
36+
37+
else:
38+
if day == 30:
39+
month += 1
40+
day = 1
41+
42+
else:
43+
day += 1
44+
45+
return year, month, day
46+
47+
48+
y, m, d = next_day(2012, 12, 1)
49+
print(y, m, d)

0 commit comments

Comments
 (0)