#===================================================================== # name: mydigit.py # # category: Python module # # description # This module defines functions that convert numbers to specified # digit numbers (e.g., 300 -> 0300) # # author # m.yoshimori (myoshimo AT ees.hokudai.ac.jp) #===================================================================== def year2yyyy(n): if n >= 10000: print "Warning in year2yyyy: The input exceeds the limit (=9999)." print "The output is set to 0000" res = "0000" elif n >= 1000: res = str(n) elif n >= 100: res = "0" + str(n) elif n >= 10: res = "00" + str(n) else: res = "000" + str(n) return res def year2yyy(n): if n >= 1000: print "Warning in year2yyy: The input exceeds the limit (=999)." print "The output is set to 000" res = "000" elif n >= 100: res = str(n) elif n >= 10: res = "0" + str(n) else: res = "00" + str(n) return res def year2yy(n): if n >= 100: print "Warning in year2yy: The input exceeds the limit (=99)." print "The output is set to 00" res = "00" elif n >= 10: res = str(n) else: res = "0" + str(n) return res