Skip to content

Commit 8ca57cc

Browse files
committed
Merge pull request Show-Me-the-Code#164 from lwhhhh/master
n
2 parents d902166 + c99df75 commit 8ca57cc

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

lwh/1/addnum.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from PIL import Image, ImageDraw
2+
from PIL import ImageFont
3+
import random
4+
5+
# 设置字体
6+
font = ImageFont.truetype("C:/Windows/Fonts/Arial.ttf", 20)
7+
8+
#打开文件
9+
im = Image.open("avatar.jpg")
10+
11+
#使用PIl的ImageDraw
12+
draw = ImageDraw.Draw(im)
13+
text = str(random.randint(1, 20))
14+
point = (180, 10)
15+
draw.text(point, text, font=font, fill="red")
16+
17+
#保存
18+
im.save("avatar2.jpg")

lwh/1/avatar.jpg

8.73 KB
Loading

lwh/2/active_code.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
做为 Apple Store App 独立开发者,你要搞限时促销,
3+
为你的应用生成激活码(或者优惠券),
4+
使用 Python 如何生成 200 个激活码(或者优惠券)?
5+
6+
激活码格式:
7+
19个字符组成,分成4组,中间用"-"连接起来
8+
必须同时包含大小写字母数字
9+
10+
"""
11+
import random
12+
import string
13+
14+
15+
def generate_active_code():
16+
active_code = []
17+
ascii_ = string.ascii_letters + string.digits
18+
active_code = ["".join([random.choice(ascii_) for i in range(16)])
19+
for i in range(200)]
20+
21+
return active_code
22+
23+
if __name__ == "__main__":
24+
active_code = generate_active_code()
25+
print(active_code)

0 commit comments

Comments
 (0)