# This file contains buggy code adapted by Max Hailperin # from code that Microsoft apparently used in its original Zune. The original # was writtten in C rather than Python and was part of a larger procedure, # but the essential control structure is as shown here. # # I've also made use of a Python library procedure, calendar.isleap(year), # to test whether year is a leap year. The original version contained # the code for a procedure to do that test. import calendar def dayToYear(days): '''Return the year corresponding to a particular day. argument: days -- the day number starting with 1 for January 1, 1980''' year = 1980 while days > 365: if calendar.isleap(year): if days > 366: days = days - 366 year = year + 1 else: days = days - 365 year = year + 1 return year