Learning Scientific Programming with Python (2nd edition)

P2.5.5: Determining tomorrow's date

Question P2.5.5

Write a program to determine tomorrow's date given a string representing today's date, today, as either 'D/M/Y' or 'M/D/Y'. Cater for both British and US-style dates when parsing today according to the value of a boolean variable us_date_style. For example, when us_date_style is False and today is '3/4/2014', tomorrow's date should be reported as '4/4/2014'.

[Note that in practice, it would be better to use Python's datetime library (described in Section 4.5.3 of the book), but avoid it for this exercise.]

Hint: use the algorithm for determining if a year is a leap year provided in the example to Section 2.5.1.