python学习之老男孩python全栈第九期_day019作业

# 计算时间差

1 import time
2 start_time = time.mktime(time.strptime('2017-09-11 08:30:00','%Y-%m-%d %H:%M:%S'))
3 end_time = time.mktime(time.strptime('2018-07-30 08:30:00','%Y-%m-%d %H:%M:%S'))
4 dif_time = end_time - start_time
5 dif_time = time.gmtime(dif_time)
6 print('过去了%d年%d月%d天%d小时%d分钟%d秒'%(dif_time.tm_year-1970,dif_time.tm_mon-1,dif_time.tm_mday-1,dif_time.tm_hour,dif_time.tm_min,dif_time.tm_sec))

 

# 验证码

 1 import random
 2 def v_code():
 3     '''
 4     验证码
 5     :return:
 6     '''
 7     code = ''
 8     for count in range(4):
 9         digit_code = random.randint(0,9)
10         word_code = chr(random.randint(65,90))
11         add_code = random.choice([digit_code,word_code])
12         code = ''.join([code,str(add_code)])
13     return code

 

posted @ 2018-07-25 21:10  李培冠  阅读(413)  评论(0编辑  收藏  举报