Skip to content

Commit d912880

Browse files
committed
n
n
1 parent 349a92a commit d912880

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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_ = list(string.ascii_letters)
18+
for i in range(200):
19+
active_code_temp = ""
20+
for j in range(19):
21+
num_or_char = random.randint(0, 1)
22+
# 用"-"连接
23+
if j == 4 or j == 9 or j == 14:
24+
active_code_temp = active_code_temp + "-"
25+
# 生成数字
26+
elif num_or_char == 0:
27+
active_code_temp = active_code_temp + str(random.randint(0, 9))
28+
# 生成字符
29+
elif num_or_char == 1:
30+
active_code_temp = active_code_temp + \
31+
str(ascii_[random.randint(0, len(ascii_) - 1)])
32+
active_code.append(active_code_temp)
33+
34+
return active_code
35+
36+
if __name__ == "__main__":
37+
active_code = generate_active_code()
38+
print(active_code)

0 commit comments

Comments
 (0)