ユーザーが日付を入力し、それを別の日付と比較してどちらが先かを確認するプログラムがあります。
ユーザーが 2 月 29 日を入力し、プログラムが代わりに 2 月 28 日を返すコードを作成するにはどうすればよいでしょうか (閏年がないため)。
例:
def date(prompt):
''' returns the date that user inputs and validates it'''
while True:
try:
date = raw_input(prompt)
if len(date) >= 5:
month = date[0:2]
day = date[3:5]
dateObject = datetime.date(2011, int(month), int(day))
return dateObject
except ValueError:
print "Please enter a valid month and day"