We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c419ad0 commit 6d3cc7fCopy full SHA for 6d3cc7f
AK-wang/0001/key_gen_deco.py
@@ -0,0 +1,37 @@
1
+#!/usr/bin/env python
2
+#-*-coding:utf-8-*-
3
+
4
+"""
5
+第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
6
7
8
+import string
9
+import random
10
11
+KEY_LEN = 20
12
+KEY_ALL = 200
13
14
+def base_str():
15
+ return (string.letters+string.digits)
16
17
+def key_gen():
18
+ keylist = [random.choice(base_str()) for i in range(KEY_LEN)]
19
+ return ("".join(keylist))
20
21
+def print_key(func):
22
+ def _print_key(num):
23
+ for i in func(num):
24
+ print i
25
+ return _print_key
26
27
+@print_key
28
+def key_num(num,result=None):
29
+ if result is None:
30
+ result = []
31
+ for i in range(num):
32
+ result.append(key_gen())
33
+ return result
34
35
+if __name__ == "__main__":
36
+ #print_key(KEY_ALL)
37
+ key_num(KEY_ALL)
0 commit comments