diff --git a/Drake-Z/0000/0000.py b/Drake-Z/0000/0000.py
new file mode 100644
index 00000000..857e7480
--- /dev/null
+++ b/Drake-Z/0000/0000.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。'
+
+__author__ = 'Drake-Z'
+
+from PIL import Image, ImageDraw, ImageFont
+
+def add_num(filname, text = '4', fillcolor = (255, 0, 0)):
+ img = Image.open(filname)
+ width, height = img.size
+ myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=width//8)
+ fillcolor = (255, 0, 0)
+ draw = ImageDraw.Draw(img)
+ draw.text((width-width//8, 0), text, font=myfont, fill=fillcolor)
+ img.save('1.jpg','jpeg')
+ return 0
+
+if __name__ == '__main__':
+ filname = '0.jpg'
+ text = '4'
+ fillcolor = (255, 0, 0)
+ add_num(filname, text, fillcolor)
\ No newline at end of file
diff --git a/Drake-Z/0001/0001.py b/Drake-Z/0001/0001.py
new file mode 100644
index 00000000..4d6b4925
--- /dev/null
+++ b/Drake-Z/0001/0001.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)'
+
+__author__ = 'Drake-Z'
+
+import random
+
+def randChar(filename, digit=4, num=200):
+ f = open(filename, 'a')
+ for i in range(0, num):
+ for m in range(0, digit):
+ f.write(chr(random.randint(65, 90)))
+ f.write('\n')
+ f.close()
+ print('Done!')
+ return 0
+
+if __name__ == '__main__':
+ filename = 'active_code.txt'
+ digit = 4
+ num = 200
+ rndChar(filename, digit, num)
\ No newline at end of file
diff --git a/Drake-Z/0002/0002.py b/Drake-Z/0002/0002.py
new file mode 100644
index 00000000..34f28723
--- /dev/null
+++ b/Drake-Z/0002/0002.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0002 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。'
+
+__author__ = 'Drake-Z'
+
+import mysql.connector
+
+def write_to_mysql(filename):
+ conn = mysql.connector.connect(user='root', password='986535', database='test')
+ cursor = conn.cursor()
+ cursor.execute("DROP TABLE IF EXISTS user")
+ cursor.execute('create table user (id varchar(20) primary key, name varchar(20))')
+ f = open(filename, 'r').readlines()
+ for line, num in zip(f, range(1, len(f)+1)):
+ line = line[:-1] #去除\n符号
+ cursor.execute('insert into user (id, name) values (%s, %s)', [str(num), line])
+ conn.commit()
+ cursor.close()
+ return 0
+
+def search_mysql():
+ b = input('Search Active code(1-200):')
+ conn = mysql.connector.connect(user='root', password='986535', database='test')
+ cursor = conn.cursor()
+ cursor.execute('select * from user where id = %s', (b,))
+ values = cursor.fetchall()
+ print(values)
+ cursor.close()
+ conn.close()
+ return 0
+
+if __name__ == '__main__':
+ filename = 'active_code.txt'
+ write_to_mysql(filename)
+ search_mysql()
\ No newline at end of file
diff --git a/Drake-Z/0003/0003.py b/Drake-Z/0003/0003.py
new file mode 100644
index 00000000..d0ab4bf4
--- /dev/null
+++ b/Drake-Z/0003/0003.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0003 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。'
+
+__author__ = 'Drake-Z'
+
+import redis
+
+def write_to_redis(filename):
+ r = redis.StrictRedis(host='localhost', port=6379, db=0)
+ r.flushdb()
+ f = open(filename, 'r').readlines()
+ for line, num in zip(f, range(1, len(f)+1)):
+ line = line[:-1] #去除\n符号
+ r.set(num, line)
+ return 0
+
+def search_redis():
+ b = int(input('Search Active code(1-200):'))
+ r = redis.StrictRedis(host='localhost', port=6379, db=0)
+ print(str(r.get(b),'UTF-8'))
+ return 0
+
+if __name__ == '__main__':
+ filename = 'active_code.txt'
+ write_to_redis(filename)
+ search_redis()
\ No newline at end of file
diff --git a/Drake-Z/0004/0004.py b/Drake-Z/0004/0004.py
new file mode 100644
index 00000000..9deb26b1
--- /dev/null
+++ b/Drake-Z/0004/0004.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。'
+
+__author__ = 'Drake-Z'
+
+import re
+
+def statistics(file_path):
+ f = open(file_path, 'r').read()
+ f = re.findall(r'[\w\-\_\.\']+', f)
+ print(len(f))
+ return 0
+
+if __name__ == '__main__':
+ file_path = 'English.txt'
+ statistics(file_path)
\ No newline at end of file
diff --git a/Drake-Z/0004/English.txt b/Drake-Z/0004/English.txt
new file mode 100644
index 00000000..197d3b49
--- /dev/null
+++ b/Drake-Z/0004/English.txt
@@ -0,0 +1,2 @@
+ConnectionPools manage a set of Connection instances. redis-py ships with two types of Connections. The default, Connection, is a normal TCP socket based connection. The UnixDomainSocketConnection allows for clients running on the same device as the server to connect via a unix domain socket.
+To use a, UnixDomainSocketConnection connection, simply pass the unix_socket_path argument, which is a string to the unix domain socket file. Additionally, make sure the unixsocket parameter is defined in your redis.conf file. It's commented out by default.
\ No newline at end of file
diff --git a/Drake-Z/0005/0005.py b/Drake-Z/0005/0005.py
new file mode 100644
index 00000000..e3d5ec85
--- /dev/null
+++ b/Drake-Z/0005/0005.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率(1136x640)的大小。'
+
+__author__ = 'Drake-Z'
+
+import os
+import glob
+from PIL import Image
+
+def thumbnail_pic(path):
+ a = glob.glob(r'*.jpg')
+ for x in a:
+ name = os.path.join(path, x)
+ im = Image.open(name)
+ im.thumbnail((1136, 640))
+ print(im.format, im.size, im.mode)
+ im.save(name, 'JPEG')
+ print('Done!')
+
+if __name__ == '__main__':
+ path = '.'
+ thumbnail_pic(path)
\ No newline at end of file
diff --git a/Drake-Z/0005/ace-94.jpg b/Drake-Z/0005/ace-94.jpg
new file mode 100644
index 00000000..636d9e94
Binary files /dev/null and b/Drake-Z/0005/ace-94.jpg differ
diff --git a/Drake-Z/0006/0006.py b/Drake-Z/0006/0006.py
new file mode 100644
index 00000000..4d120596
--- /dev/null
+++ b/Drake-Z/0006/0006.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。'
+
+__author__ = 'Drake-Z'
+
+import os
+import re
+import glob
+from collections import OrderedDict
+
+def get_num(key_word, filename):
+ '''获得词汇出现次数'''
+ f = open(filename, 'r', encoding='utf-8').read()
+ re_zhengze = re.compile(r'[\s\,\;\.\n]{1}'+key_word+r'[\s\,\;\.\n]{1}')
+ numbers = re_zhengze.findall(f)
+ return len(numbers)
+
+def article_analysis(dirs):
+ article = glob.glob(r'*.txt')
+ dictdata = OrderedDict()
+ for m in article:
+ doc = open(m, 'r', encoding='utf-8').read()
+ doc = re.findall(r'[\w\-\_\.\']+', doc) #获得单词list
+ doc = list(map(lambda x: x.strip('.'), doc)) #去除句号
+ for n in doc:
+ dictdata[n] = get_num(n, m)
+ a = OrderedDict(sorted(dictdata.items(), key=lambda x: x[1], reverse = True)) #dict排序
+ print('在 %s 中出现次数最多的单词是:' % m)
+ for c in a:
+ print(c+' : %s 次' % a[c])
+ break
+ return 0
+
+if __name__ == '__main__':
+ file = '.'
+ article_analysis(file)
diff --git a/Drake-Z/0006/001.txt b/Drake-Z/0006/001.txt
new file mode 100644
index 00000000..53eff756
--- /dev/null
+++ b/Drake-Z/0006/001.txt
@@ -0,0 +1 @@
+You are not so absorbed about them. You see them for their flaws and perfections. Since you can rely on your instincts and find other pleasures, rather than just within the relationship itself, you understand your partner better. This knowledge will prove beneficial in the way you treat them.
\ No newline at end of file
diff --git a/Drake-Z/0006/002.txt b/Drake-Z/0006/002.txt
new file mode 100644
index 00000000..e4d26f04
--- /dev/null
+++ b/Drake-Z/0006/002.txt
@@ -0,0 +1,3 @@
+Being in a relationship can be a full-time job. Sometimes, it can become so overwhelming and consuming that you lose your own voice and sense of ownership. You want freedom and you think your partner is not making you happy enough. You question why you are in the relationship at all.
+
+Yes, we all need that moment to feel uneasy and track our direction in whatever relationship we’re in. These breaks can be beneficial to becoming the person you want to be. Here are some of the positive things that can come out of those moments of indecision.
\ No newline at end of file
diff --git a/Drake-Z/0006/003.txt b/Drake-Z/0006/003.txt
new file mode 100644
index 00000000..69306767
--- /dev/null
+++ b/Drake-Z/0006/003.txt
@@ -0,0 +1,4 @@
+Being lost can offer you freedom. You identify your core values, desires, and tastes. You are open with yourself and you can try new things. You understand that you do not have to always rely on your partner. Perhaps there is a movie coming out this weekend, you can buy a ticket and go to the cinemas yourself — something that may have been unheard of for you in the past. Being forced to find this independence can make you a stronger person.
+You can disconnect. You are no longer driven by the interests of your partner, but by your own desires. This means getting back to the basics, like reading books by your favorite author, exercising, eating your favorite meals. When you return to these ideals, you are strengthened and become a better you.
+
+People think that being lost in a relationship signals doom for that relationship — it doesn’t. It all depends on how you manage this necessary stage and work towards making the most of it.
\ No newline at end of file
diff --git a/Drake-Z/0007/0007.py b/Drake-Z/0007/0007.py
new file mode 100644
index 00000000..53a1cd3a
--- /dev/null
+++ b/Drake-Z/0007/0007.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0007 题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。'
+
+__author__ = 'Drake-Z'
+
+import os
+import re
+
+def count_num(a, b):
+ shuzi = [0, 0, 0]
+ path = os.path.join(a, b)
+ f = open(path, 'r', encoding='UTF-8').readlines()
+ for i in f:
+ if re.match(r'^#', i) == None:
+ pass
+ else:
+ shuzi[1] += 1 #获得注释行数,只匹配单行注释
+ if f[-1][-1:]=='\n': #最后一行为空行时
+ shuzi[2] = f.count('\n')+1 #获得空行行数
+ shuzi[0] = len(f)+1 - shuzi[2] - shuzi[1] #获得代码行数
+ else:
+ shuzi[2] = f.count('\n')
+ shuzi[0] = len(f) - shuzi[2] - shuzi[1]
+ return shuzi
+
+def file_analysis(c, d):
+ py = [x for x in os.listdir(c) if os.path.splitext(x)[1]==d] #获得文件列表
+ print(py)
+ the_num = [0, 0, 0]
+ for i in py:
+ num = count_num(c, i)
+ the_num[0] += num[0] #累计
+ the_num[1] += num[1]
+ the_num[2] += num[2]
+ print('''统计得目录中:
+ 代码有 %s 行
+ 注释 %s 行
+ 空行 %s 行''' % (the_num[0], the_num[1], the_num[2]))
+
+if __name__ == '__main__':
+ file = '.'
+ ext = '.py'
+ file_analysis(file, ext)
\ No newline at end of file
diff --git a/Drake-Z/0007/test.py b/Drake-Z/0007/test.py
new file mode 100644
index 00000000..f66f4a56
--- /dev/null
+++ b/Drake-Z/0007/test.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# mydict_test.py
+
+import unittest
+from MyMoudel.Moudel1 import Dict
+class TestDict(unittest.TestCase):
+
+ def test_init(self):
+ d = Dict(a=1, b='test')
+ self.assertEqual(d.a, 1)
+ self.assertEqual(d.b, 'test')
+ self.assertTrue(isinstance(d, dict))
+
+ def test_key(self):
+ d = Dict()
+ d['key'] = 'value'
+ self.assertEqual(d.key, 'value')
+
+ def test_attr(self):
+ d = Dict()
+ d.key = 'value'
+ self.assertTrue('key' in d)
+ self.assertEqual(d['key'], 'value')
+
+ def test_keyerror(self):
+ d = Dict()
+ with self.assertRaises(KeyError):
+ value = d['empty']
+
+ def test_attrerror(self):
+ d = Dict()
+ with self.assertRaises(AttributeError):
+ value = d.empty
+
+ def setUp(self):
+ print('setUp...')
+
+ def tearDown(self):
+ print('tearDown...')
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/Drake-Z/0008/0008.py b/Drake-Z/0008/0008.py
new file mode 100644
index 00000000..009a2712
--- /dev/null
+++ b/Drake-Z/0008/0008.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0008 题:一个HTML文件,找出里面的正文。'
+
+__author__ = 'Drake-Z'
+
+from html.parser import HTMLParser
+from html.entities import name2codepoint
+
+class MyHTMLParser(HTMLParser):
+ in_zhengwen = False
+ in_huanhang = False
+ def handle_starttag(self, tag, attrs):
+ if ('class', 'zh-summary summary clearfix') in attrs and tag=='div' :
+ self.in_zhengwen = True
+ elif ('class', 'zm-editable-content clearfix') in attrs and tag=='div' :
+ self.in_zhengwen = True
+ elif tag=='br':
+ print('\n')
+ else:
+ self.in_zhengwen = False
+
+ def handle_data(self, data):
+ if self.in_zhengwen:
+ print(data.strip())
+ else:
+ pass
+
+if __name__ == '__main__':
+ parser = MyHTMLParser()
+ f = open('test.html', 'r', encoding = 'utf-8').read()
+ parser.feed(f)
\ No newline at end of file
diff --git a/Drake-Z/0009/0009.py b/Drake-Z/0009/0009.py
new file mode 100644
index 00000000..19975694
--- /dev/null
+++ b/Drake-Z/0009/0009.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0009 题:一个HTML文件,找出里面的链接。'
+
+__author__ = 'Drake-Z'
+
+import os, re
+from html.parser import HTMLParser
+from html.entities import name2codepoint
+
+class MyHTMLParser(HTMLParser):
+
+ def handle_starttag(self, tag, attrs):
+ if tag == 'a':
+ for (variables, value) in attrs:
+ if variables == 'href':
+ if re.match(r'http(.*?)', value):
+ print(value)
+
+if __name__ == '__main__':
+ with open('test.html', encoding='utf-8') as html:
+ parser = MyHTMLParser()
+ parser.feed(html.read())
\ No newline at end of file
diff --git a/Drake-Z/0010/0010.py b/Drake-Z/0010/0010.py
new file mode 100644
index 00000000..d229f45e
--- /dev/null
+++ b/Drake-Z/0010/0010.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0010 题:使用 Python 生成类似于图中的字母验证码图片'
+
+from PIL import Image, ImageDraw, ImageFont, ImageFilter
+
+import random
+
+# 随机字母:
+def rndChar():
+ return chr(random.randint(65, 90))
+
+# 随机颜色1:
+def rndColor():
+ return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255))
+
+# 随机颜色2:
+def rndColor2():
+ return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127))
+
+# 240 x 60:
+width = 60 * 4
+height = 60
+image = Image.new('RGB', (width, height), (255, 255, 255))
+# 创建Font对象:
+font = ImageFont.truetype('C:\Windows\Fonts\Arial.ttf', 36)
+# 创建Draw对象:
+draw = ImageDraw.Draw(image)
+# 填充每个像素:
+for x in range(width):
+ for y in range(height):
+ draw.point((x, y), fill=rndColor())
+# 输出文字:
+for t in range(4):
+ draw.text((60 * t + 10, 10), rndChar(), font=font, fill=rndColor2())
+# 模糊:
+image = image.filter(ImageFilter.BLUR)
+image.save('0010\code.jpg', 'jpeg')
\ No newline at end of file
diff --git a/Drake-Z/0011/0011.py b/Drake-Z/0011/0011.py
new file mode 100644
index 00000000..510f3e92
--- /dev/null
+++ b/Drake-Z/0011/0011.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。'
+
+__author__ = 'Drake-Z'
+
+import os
+import re
+
+def filter_word(a):
+
+ f = open('filtered_words.txt', 'r', encoding = 'utf-8').read()
+ if a == '':
+ print('Human Rights !')
+ elif len(re.findall(r'%s' % (a), f)) == 0:
+ print('Human Rights !') #非敏感词时,则打印出 Human Rights !
+ else:
+ print('Freedom !') #输入敏感词语打印出 Freedom !
+
+z = input('请输入词语:')
+filter_word(z)
\ No newline at end of file
diff --git a/Drake-Z/0011/filtered_words.txt b/Drake-Z/0011/filtered_words.txt
new file mode 100644
index 00000000..69373b64
--- /dev/null
+++ b/Drake-Z/0011/filtered_words.txt
@@ -0,0 +1,11 @@
+北京
+程序员
+公务员
+领导
+牛比
+牛逼
+你娘
+你妈
+love
+sex
+jiangge
\ No newline at end of file
diff --git a/Drake-Z/0012/0012.py b/Drake-Z/0012/0012.py
new file mode 100644
index 00000000..e0f2fadf
--- /dev/null
+++ b/Drake-Z/0012/0012.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。'
+
+__author__ = 'Drake-Z'
+
+import os
+import re
+
+def filter_word(a):
+ sensitive = False
+ strs = '**'
+ f = open('filtered_words.txt', 'r', encoding = 'utf-8').readlines()
+ for i in f:
+ i = i.strip() #去除\n
+ b = re.split(r'%s' % (i), a) #分解字符串
+ if len(b) > 1:
+ c = i
+ sensitive = True
+ else:
+ pass
+ if sensitive == True:
+ b = re.split(r'%s' % (c.strip()), a)
+ print(strs.join(b))
+ else:
+ print(a)
+ return 0
+
+z = input('请输入:')
+filter_word(z)
\ No newline at end of file
diff --git a/Drake-Z/0012/filtered_words.txt b/Drake-Z/0012/filtered_words.txt
new file mode 100644
index 00000000..69373b64
--- /dev/null
+++ b/Drake-Z/0012/filtered_words.txt
@@ -0,0 +1,11 @@
+北京
+程序员
+公务员
+领导
+牛比
+牛逼
+你娘
+你妈
+love
+sex
+jiangge
\ No newline at end of file
diff --git a/Drake-Z/0013/0013.py b/Drake-Z/0013/0013.py
new file mode 100644
index 00000000..f3a17d30
--- /dev/null
+++ b/Drake-Z/0013/0013.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'第 0013 题: 用 Python 写一个爬图片的程序,爬(http://tieba.baidu.com/p/2166231880)图片 :-)'
+
+__author__ = 'Drake-Z'
+
+import os
+import re
+import urllib
+from urllib import request
+from urllib.request import urlopen
+
+def read_url(yuanshiurl):
+ req = request.Request(yuanshiurl)
+ req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; 360SE /360/ /chrome/ig)')
+ with request.urlopen(req) as f:
+ Imageurl(f.read().decode('utf-8')) #输出Data
+ return 0
+
+def Imageurl(data):
+ re_Imageurl = re.compile(r'src="(http://imgsrc.baidu.com/forum/.*?)"')
+ data = re_Imageurl.findall(data) #输出图片链接
+ downloadImage(data)
+
+def downloadImage(pic_url):
+ dirct = '0013'
+ try:
+ if not os.path.exists(dirct): #创建存放目录
+ os.mkdir(dirct)
+ except:
+ print('Failed to create directory in %s' % dirct)
+ exit()
+ for i in pic_url:
+ data = urllib.request.urlopen(i).read()
+ i = re.split('/', i)[-1]
+ print(i)
+ path = dirct + '/' +i
+ f = open(path, 'wb')
+ f.write(data)
+ f.close()
+ print('Done !')
+
+url = 'http://tieba.baidu.com/p/2166231880'
+read_url(url)
\ No newline at end of file
diff --git a/Drake-Z/0014/0014.py b/Drake-Z/0014/0014.py
new file mode 100644
index 00000000..c0df4222
--- /dev/null
+++ b/Drake-Z/0014/0014.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0014 题: 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示:
+{
+ "1":["张三",150,120,100],
+ "2":["李四",90,99,95],
+ "3":["王五",60,66,68]
+}
+请将上述内容写到 student.xls 文件中。'''
+
+__author__ = 'Drake-Z'
+
+import json
+from collections import OrderedDict
+from openpyxl import Workbook
+
+def txt_to_xlsx(filename):
+ file = open(filename, 'r', encoding = 'UTF-8')
+ file_cintent = json.load(file, encoding = 'UTF-8')
+ print(file_cintent)
+ workbook = Workbook()
+ worksheet = workbook.worksheets[0]
+ for i in range(1, len(file_cintent)+1):
+ worksheet.cell(row = i, column = 1).value = i
+ for m in range(0, len(file_cintent[str(i)])):
+ worksheet.cell(row = i, column = m+2).value = file_cintent[str(i)][m]
+ workbook.save(filename = 'student.xls')
+
+if __name__ == '__main__':
+ txt_to_xlsx('student.txt')
diff --git a/Drake-Z/0015/0015.py b/Drake-Z/0015/0015.py
new file mode 100644
index 00000000..1541d123
--- /dev/null
+++ b/Drake-Z/0015/0015.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0015 题: 纯文本文件 city.txt为城市信息, 里面的内容(包括花括号)如下所示:
+{
+ "1" : "上海",
+ "2" : "北京",
+ "3" : "成都"
+}
+请将上述内容写到 city.xls 文件中。'''
+
+__author__ = 'Drake-Z'
+
+import json
+from collections import OrderedDict
+from openpyxl import Workbook
+
+def txt_to_xlsx(filename):
+ file = open(filename, 'r', encoding = 'UTF-8')
+ file_cintent = json.load(file, encoding = 'UTF-8')
+ print(file_cintent)
+ workbook = Workbook()
+ worksheet = workbook.worksheets[0]
+ for i in range(1, len(file_cintent)+1):
+ worksheet.cell(row = i, column = 1).value = i
+ worksheet.cell(row = i, column = 2).value = file_cintent[str(i)]
+ workbook.save(filename = 'city.xls')
+
+if __name__ == '__main__':
+ txt_to_xlsx('city.txt')
\ No newline at end of file
diff --git a/Drake-Z/0016/0016.py b/Drake-Z/0016/0016.py
new file mode 100644
index 00000000..b815b754
--- /dev/null
+++ b/Drake-Z/0016/0016.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0016 题: 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
+[
+ [1, 82, 65535],
+ [20, 90, 13],
+ [26, 809, 1024]
+]
+请将上述内容写到 numbers.xls 文件中。'''
+
+__author__ = 'Drake-Z'
+
+import json
+from openpyxl import Workbook
+
+def txt_to_xlsx(filename):
+ file = open(filename, 'r', encoding = 'UTF-8')
+ file_cintent = json.load(file, encoding = 'UTF-8')
+ print(file_cintent)
+ workbook = Workbook()
+ worksheet = workbook.worksheets[0]
+ for i in range(1, len(file_cintent)+1):
+ for m in range(1, len(file_cintent[i-1])+1):
+ worksheet.cell(row = i, column = m).value = file_cintent[i-1][m-1]
+ workbook.save(filename = 'numbers.xls')
+
+if __name__ == '__main__':
+ txt_to_xlsx('numbers.txt')
\ No newline at end of file
diff --git a/Drake-Z/0017/0017.py b/Drake-Z/0017/0017.py
new file mode 100644
index 00000000..baf773ce
--- /dev/null
+++ b/Drake-Z/0017/0017.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0017 题: 将 第 0014 题中的 student.xls 文件中的内容写到 student.xml 文件中,如
+下所示:
+
+
+
+
+{
+ "1" : ["张三", 150, 120, 100],
+ "2" : ["李四", 90, 99, 95],
+ "3" : ["王五", 60, 66, 68]
+}
+
+'''
+
+__author__ = 'Drake-Z'
+
+import xlrd,codecs
+from lxml import etree
+from collections import OrderedDict
+
+def read_xls(filename):
+ data = xlrd.open_workbook(filename)
+ table = data.sheets()[0]
+ c = OrderedDict()
+ for i in range(table.nrows):
+ c[table.cell(i,0).value] = table.row_values(i)[1:]
+ return c
+
+def save_xml(data):
+ output = codecs.open('student.xml','w','utf-8')
+ root = etree.Element('root')
+ student_xml = etree.ElementTree(root)
+ student = etree.SubElement(root, 'student')
+ student.append(etree.Comment('学生信息表\n\"id\": [名字,数学,语文,英语]'))
+ student.text = str(data)
+ output.write(etree.tounicode(student_xml.getroot()))
+ output.close()
+
+if __name__ == '__main__':
+ file = 'student.xls'
+ a = read_xls(file)
+ save_xml(a)
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Drake-Z/0018/0018.py b/Drake-Z/0018/0018.py
new file mode 100644
index 00000000..97a6db98
--- /dev/null
+++ b/Drake-Z/0018/0018.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0018 题: 将 第 0015 题中的 city.xls 文件中的内容写到 city.xml 文件中,如下所示:
+
+
+
+
+{
+ "1" : "上海",
+ "2" : "北京",
+ "3" : "成都"
+}
+
+'''
+
+__author__ = 'Drake-Z'
+
+import xlrd,codecs
+from lxml import etree
+from collections import OrderedDict
+
+def read_xls(filename):
+ data = xlrd.open_workbook(filename)
+ table = data.sheets()[0]
+ c = OrderedDict()
+ for i in range(table.nrows):
+ c[table.cell(i,0).value] = table.row_values(i)[1:]
+ return c
+
+def save_xml(data):
+ output = codecs.open('city.xml','w','utf-8')
+ root = etree.Element('root')
+ city_xml = etree.ElementTree(root)
+ city = etree.SubElement(root, 'city')
+ city.append(etree.Comment('城市信息'))
+ city.text = str(data)
+ output.write(etree.tounicode(city_xml.getroot()))
+ output.close()
+
+if __name__ == '__main__':
+ file = 'city.xls'
+ a = read_xls(file)
+ save_xml(a)
\ No newline at end of file
diff --git a/Drake-Z/0019/0019.py b/Drake-Z/0019/0019.py
new file mode 100644
index 00000000..c0fde199
--- /dev/null
+++ b/Drake-Z/0019/0019.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0019 题: 将 第 0016 题中的 numbers.xls 文件中的内容写到 numbers.xml 文件中,如下
+所示:
+
+
+
+
+[
+ [1, 82, 65535],
+ [20, 90, 13],
+ [26, 809, 1024]
+]
+
+'''
+
+__author__ = 'Drake-Z'
+
+import xlrd,codecs
+from lxml import etree
+from collections import OrderedDict
+
+def read_xls(filename):
+ data = xlrd.open_workbook(filename)
+ table = data.sheets()[0]
+ c = OrderedDict()
+ for i in range(table.nrows):
+ c[table.cell(i,0).value] = table.row_values(i)[1:]
+ return c
+
+def save_xml(data):
+ output = codecs.open('numbers.xml','w','utf-8')
+ root = etree.Element('root')
+ numbers_xml = etree.ElementTree(root)
+ numbers = etree.SubElement(root, 'numbers')
+ numbers.append(etree.Comment('城市信息'))
+ numbers.text = str(data)
+ output.write(etree.tounicode(numbers_xml.getroot()))
+ output.close()
+
+if __name__ == '__main__':
+ file = 'numbers.xls'
+ a = read_xls(file)
+ save_xml(a)
\ No newline at end of file
diff --git a/Drake-Z/0020/0020.py b/Drake-Z/0020/0020.py
new file mode 100644
index 00000000..98d2062b
--- /dev/null
+++ b/Drake-Z/0020/0020.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0020 题: 登陆中国联通网上营业厅 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。'''
+
+__author__ = 'Drake-Z'
+
+import os
+import re
+import xlrd
+
+def jishu(file):
+ data = xlrd.open_workbook(file)
+ table = data.sheets()[0]
+ re_timesec = re.compile(r'([\d]+)秒')
+ re_timemin = re.compile(r'([\d]+)分')
+ row_nums = table.nrows
+ numbers = 0
+ for i in range(0, row_nums):
+ a = re_timesec.findall(table.cell(i, 3).value)
+ b = re_timemin.findall(table.cell(i, 3).value)
+ if len(a)==0 : pass
+ else:
+ numbers += int(a[0])
+ if len(b)==0 : pass
+ else:
+ numbers += int(b[0])*60
+
+ print('您本月通话时长总时:%s 分 %s 秒' % (numbers//60, numbers%60))
+
+file = '语音通信.xls'
+jishu(file)
\ No newline at end of file
diff --git a/Drake-Z/0021/0021.py b/Drake-Z/0021/0021.py
new file mode 100644
index 00000000..bab3c856
--- /dev/null
+++ b/Drake-Z/0021/0021.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0021 题: 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?请使用 Python 对密码加密。'''
+
+__author__ = 'Drake-Z'
+
+import hashlib
+from collections import defaultdict
+db = {}
+db = defaultdict(lambda: 'N/A') #去掉登录可能产生的KeyError
+
+def get_md5(password):
+ a = hashlib.md5()
+ a.update(password . encode('utf-8'))
+ return (a.hexdigest())
+
+def register(username, password):
+ db[username] = get_md5(password + username + 'the-Salt')
+
+def login(username, password):
+ b = get_md5(password + username + 'the-Salt' )
+ if b==db[username]:
+ return True
+ else:
+ return False
+a = input('注册输入用户名:')
+b = input('注册输入密码:')
+register(a, b)
+a = input('登录输入用户名:')
+b = input('登录输入密码:')
+print(login(a, b))
\ No newline at end of file
diff --git a/Drake-Z/0022/0022.py b/Drake-Z/0022/0022.py
new file mode 100644
index 00000000..d7f22de5
--- /dev/null
+++ b/Drake-Z/0022/0022.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+'''第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。'''
+
+__author__ = 'Drake-Z'
+
+from PIL import Image
+import os
+
+def thumbnail_pic(a, b =1136, c=640):
+ for x in a:
+ name = os.path.join('.', x)
+ im = Image.open(name)
+ print('Before:'+im.format, im.size, im.mode)
+ im.thumbnail((b, c))
+ print('After:'+im.format, im.size, im.mode)
+ im.save(name, 'JPEG')
+
+a = os.listdir('.')
+PHONE = {'iPhone5':(1136,640), 'iPhone6':(1134,750), 'iPhone6P':(2208,1242)}
+width,height = PHONE['iPhone6']
+thumbnail_pic(a, width, height)
\ No newline at end of file