做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
考虑到选择字母和数字的问题,我用了随机生成0,1 去制定选择字母或者数字。
git上有别的朋友用的是str=‘qwertyuiopasdfghjklzxcvbnm1234567890’
然后用random.choice()去选择的
import random
def activenum(n:int,len_num:int):
b = []
for i in range(n):
S = ''
for j in range(len_num):
chr_num = random.randint(0,1) #随机选择字母或者数字
if chr_num == 0 :
ch = chr(random.randint(65,90))
else:
ch = random.randint(0,9)
S += str(ch)
print(S)
b.append(S)
return b
习题来源于github
https://github.com/Yixiaohan/show-me-the-code