Skip to content

Commit 18cb696

Browse files
committed
Add 0020-0022
1 parent 7586c8d commit 18cb696

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

Drake-Z/0020/0020.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
'''第 0020 题: 登陆中国联通网上营业厅 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。'''
5+
6+
__author__ = 'Drake-Z'
7+
8+
import os
9+
import re
10+
import xlrd
11+
12+
def jishu(file):
13+
data = xlrd.open_workbook(file)
14+
table = data.sheets()[0]
15+
re_timesec = re.compile(r'([\d]+)秒')
16+
re_timemin = re.compile(r'([\d]+)分')
17+
row_nums = table.nrows
18+
numbers = 0
19+
for i in range(0, row_nums):
20+
a = re_timesec.findall(table.cell(i, 3).value)
21+
b = re_timemin.findall(table.cell(i, 3).value)
22+
if len(a)==0 : pass
23+
else:
24+
numbers += int(a[0])
25+
if len(b)==0 : pass
26+
else:
27+
numbers += int(b[0])*60
28+
29+
print('您本月通话时长总时:%s 分 %s 秒' % (numbers//60, numbers%60))
30+
31+
file = '语音通信.xls'
32+
jishu(file)

Drake-Z/0021/0021.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
'''第 0021 题: 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?请使用 Python 对密码加密。'''
5+
6+
__author__ = 'Drake-Z'
7+
8+
import hashlib
9+
from collections import defaultdict
10+
db = {}
11+
db = defaultdict(lambda: 'N/A') #去掉登录可能产生的KeyError
12+
13+
def get_md5(password):
14+
a = hashlib.md5()
15+
a.update(password . encode('utf-8'))
16+
return (a.hexdigest())
17+
18+
def register(username, password):
19+
db[username] = get_md5(password + username + 'the-Salt')
20+
21+
def login(username, password):
22+
b = get_md5(password + username + 'the-Salt' )
23+
if b==db[username]:
24+
return True
25+
else:
26+
return False
27+
a = input('注册输入用户名:')
28+
b = input('注册输入密码:')
29+
register(a, b)
30+
a = input('登录输入用户名:')
31+
b = input('登录输入密码:')
32+
print(login(a, b))

Drake-Z/0022/0022.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
'''第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。'''
5+
6+
__author__ = 'Drake-Z'
7+
8+
from PIL import Image
9+
import os
10+
11+
def thumbnail_pic(a, b =1136, c=640):
12+
for x in a:
13+
name = os.path.join('.', x)
14+
im = Image.open(name)
15+
print('Before:'+im.format, im.size, im.mode)
16+
im.thumbnail((b, c))
17+
print('After:'+im.format, im.size, im.mode)
18+
im.save(name, 'JPEG')
19+
20+
a = os.listdir('.')
21+
PHONE = {'iPhone5':(1136,640), 'iPhone6':(1134,750), 'iPhone6P':(2208,1242)}
22+
width,height = PHONE['iPhone6']
23+
thumbnail_pic(a, width, height)

0 commit comments

Comments
 (0)