登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
6.22: import time def isleapyear(): for i in range(1970,2020): if (i % 4 ==0 and i % 100 !=0) or (i % 400 ==0): return True def month(years,days): if days - 31 > 0: days-=31 if (years% 4 ==0 and years % 100 !=0) or (years % 400 ==0): if days - 29 >0: days-=29 if days - 31 > 0 : days-=31 if days - 30 >0: days-=30 if days - 31 > 0: days-=31 if days - 30>0: days-=30 if days - 31 > 0: days-=31 if days - 31 >0: days-=31 if days - 30 >0: days-=30 if days - 31 >0: days-=31 if days - 30 >0: days-=30 return 12,days else: return 11,days else: return 10,days else: return 9,days else: return 8,days else: return 7,days else: return 6,days else: return 5,days else: return 4,days else: return 3,days else: return 2,days else: if days - 28 >0: days-=28 if days - 31 > 0 : days-=31 if days - 30 >0: days-=30 if days - 31 > 0: days-=31 if days - 30>0: days-=30 if days - 31 > 0: days-=31 if days - 31 >0: days-=31 if days - 30 >0: days-=30 if days - 31 >0: days-=31 if days - 30 >0: days-=30 return 12,days else: return 11,days else: return 10,days else: return 9,days else: return 8,days else: return 7,days else: return 6,days else: return 5,days else: return 4,days else: return 3,days else: return 2,days else: return 1,days def date(): start=int(time.time()) seconds=start % 60 minitues=start // 60 hours=minitues // 60 minitues=minitues % 60 days=hours // 24 hours=hours % 24 count=0 while days > 365: if isleapyear(): days-=366 count+=1 else: days-=365 count+=1 years=1970+count months,days=month(years,days) return years , months , days , hours , minitues ,seconds print(date()) def main(): years,months,days,hours,minitues,seconds=date() print(str(years)+'-'+str(months)+'-'+str(days)+'-'+str(hours)+':'+str(minitues)+':'+str(seconds)) main() 6.23: def convertMillis(millis): millis/=1000 seconds=int(millis % 60) miniutes=millis // 60 hours=int(miniutes // 60) miniutes=int(miniutes % 60) return hours , miniutes , seconds def main(millis): hours,miniutes,seconds=convertMillis(millis) print(str(hours)+':'+str(miniutes)+':'+str(seconds)) main(eval(input('millis:'))) 6.24:回文素数: def isprime(number): isprime=True i=2 while i < number: if number % i ==0: isprime=False i+=1 return isprime def reverse(number): remainder='' a=number while number != 0 : remainder=remainder+str(number % 10) number=number // 10 if int(remainder)==a: return True else: return False count=0 j=2 while count < 100 : if isprime(j) and reverse(j): print(format(j,'6d'),end=' ') count+=1 if count % 10 ==0: print() j+=1
|