99import time
1010import calendar
1111
12- def raw_input (prompt ):
13- sys .stdout .write (prompt )
14- sys .stdout .flush ()
15- return sys .stdin .readline ()
16-
1712def main ():
18- # Note that the range checks below also check for bad types,
19- # e.g. 3.14 or (). However syntactically invalid replies
20- # will raise an exception.
2113 if sys .argv [1 :]:
2214 year = int (sys .argv [1 ])
2315 else :
2416 year = int (input ('In which year were you born? ' ))
25- if 0 <= year < 100 :
17+ if 0 <= year < 100 :
2618 print ("I'll assume that by" , year , end = ' ' )
2719 year = year + 1900
2820 print ('you mean' , year , 'and not the early Christian era' )
29- elif not (1850 <= year <= 2002 ):
21+ elif not (1850 <= year <= time . localtime ()[ 0 ] ):
3022 print ("It's hard to believe you were born in" , year )
3123 return
32- #
24+
3325 if sys .argv [2 :]:
3426 month = int (sys .argv [2 ])
3527 else :
3628 month = int (input ('And in which month? (1-12) ' ))
37- if not (1 <= month <= 12 ):
29+ if not (1 <= month <= 12 ):
3830 print ('There is no month numbered' , month )
3931 return
40- #
32+
4133 if sys .argv [3 :]:
4234 day = int (sys .argv [3 ])
4335 else :
@@ -46,45 +38,45 @@ def main():
4638 maxday = 29
4739 else :
4840 maxday = calendar .mdays [month ]
49- if not (1 <= day <= maxday ):
41+ if not (1 <= day <= maxday ):
5042 print ('There are no' , day , 'days in that month!' )
5143 return
52- #
44+
5345 bdaytuple = (year , month , day )
5446 bdaydate = mkdate (bdaytuple )
5547 print ('You were born on' , format (bdaytuple ))
56- #
48+
5749 todaytuple = time .localtime ()[:3 ]
5850 todaydate = mkdate (todaytuple )
5951 print ('Today is' , format (todaytuple ))
60- #
52+
6153 if bdaytuple > todaytuple :
6254 print ('You are a time traveler. Go back to the future!' )
6355 return
64- #
56+
6557 if bdaytuple == todaytuple :
6658 print ('You were born today. Have a nice life!' )
6759 return
68- #
60+
6961 days = todaydate - bdaydate
7062 print ('You have lived' , days , 'days' )
71- #
63+
7264 age = 0
7365 for y in range (year , todaytuple [0 ] + 1 ):
7466 if bdaytuple < (y , month , day ) <= todaytuple :
7567 age = age + 1
76- #
68+
7769 print ('You are' , age , 'years old' )
78- #
70+
7971 if todaytuple [1 :] == bdaytuple [1 :]:
8072 print ('Congratulations! Today is your' , nth (age ), 'birthday' )
8173 print ('Yesterday was your' , end = ' ' )
8274 else :
8375 print ('Today is your' , end = ' ' )
8476 print (nth (days - age ), 'unbirthday' )
8577
86- def format (xxx_todo_changeme ):
87- (year , month , day ) = xxx_todo_changeme
78+ def format (date ):
79+ (year , month , day ) = date
8880 return '%d %s %d' % (day , calendar .month_name [month ], year )
8981
9082def nth (n ):
@@ -93,12 +85,12 @@ def nth(n):
9385 if n == 3 : return '3rd'
9486 return '%dth' % n
9587
96- def mkdate (xxx_todo_changeme1 ):
97- # Januari 1st, in 0 A.D. is arbitrarily defined to be day 1,
88+ def mkdate (date ):
89+ # January 1st, in 0 A.D. is arbitrarily defined to be day 1,
9890 # even though that day never actually existed and the calendar
9991 # was different then...
100- (year , month , day ) = xxx_todo_changeme1
101- days = year * 365 # years, roughly
92+ (year , month , day ) = date
93+ days = year * 365 # years, roughly
10294 days = days + (year + 3 )// 4 # plus leap years, roughly
10395 days = days - (year + 99 )// 100 # minus non-leap years every century
10496 days = days + (year + 399 )// 400 # plus leap years every 4 centirues
0 commit comments