Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Demo/scripts/unbirthday.py

    r2 r391  
    1111
    1212def main():
    13     # Note that the range checks below also check for bad types,
    14     # e.g. 3.14 or ().  However syntactically invalid replies
    15     # will raise an exception.
    1613    if sys.argv[1:]:
    1714        year = int(sys.argv[1])
    1815    else:
    1916        year = int(raw_input('In which year were you born? '))
    20     if 0<=year<100:
     17    if 0 <= year < 100:
    2118        print "I'll assume that by", year,
    2219        year = year + 1900
    2320        print 'you mean', year, 'and not the early Christian era'
    24     elif not (1850<=year<=2002):
     21    elif not (1850 <= year <= time.localtime()[0]):
    2522        print "It's hard to believe you were born in", year
    2623        return
    27     #
     24
    2825    if sys.argv[2:]:
    2926        month = int(sys.argv[2])
    3027    else:
    3128        month = int(raw_input('And in which month? (1-12) '))
    32     if not (1<=month<=12):
     29    if not (1 <= month <= 12):
    3330        print 'There is no month numbered', month
    3431        return
    35     #
     32
    3633    if sys.argv[3:]:
    3734        day = int(sys.argv[3])
     
    4239    else:
    4340        maxday = calendar.mdays[month]
    44     if not (1<=day<=maxday):
     41    if not (1 <= day <= maxday):
    4542        print 'There are no', day, 'days in that month!'
    4643        return
    47     #
     44
    4845    bdaytuple = (year, month, day)
    4946    bdaydate = mkdate(bdaytuple)
    5047    print 'You were born on', format(bdaytuple)
    51     #
     48
    5249    todaytuple = time.localtime()[:3]
    5350    todaydate = mkdate(todaytuple)
    5451    print 'Today is', format(todaytuple)
    55     #
     52
    5653    if bdaytuple > todaytuple:
    5754        print 'You are a time traveler.  Go back to the future!'
    5855        return
    59     #
     56
    6057    if bdaytuple == todaytuple:
    6158        print 'You were born today.  Have a nice life!'
    6259        return
    63     #
     60
    6461    days = todaydate - bdaydate
    6562    print 'You have lived', days, 'days'
    66     #
     63
    6764    age = 0
    6865    for y in range(year, todaytuple[0] + 1):
    6966        if bdaytuple < (y, month, day) <= todaytuple:
    7067            age = age + 1
    71     #
     68
    7269    print 'You are', age, 'years old'
    73     #
     70
    7471    if todaytuple[1:] == bdaytuple[1:]:
    7572        print 'Congratulations!  Today is your', nth(age), 'birthday'
     
    8986
    9087def mkdate((year, month, day)):
    91     # Januari 1st, in 0 A.D. is arbitrarily defined to be day 1,
     88    # January 1st, in 0 A.D. is arbitrarily defined to be day 1,
    9289    # even though that day never actually existed and the calendar
    9390    # was different then...
    94     days = year*365                 # years, roughly
     91    days = year*365                  # years, roughly
    9592    days = days + (year+3)//4        # plus leap years, roughly
    9693    days = days - (year+99)//100     # minus non-leap years every century
Note: See TracChangeset for help on using the changeset viewer.