题目链接
https://github.com/Yixiaohan/show-me-the-code?utm_source=wechat_session&utm_medium=social&utm_oi=722728239742615552
0001
做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
#随机生成激活码
#未考虑重复码,数字出现1/5概率,大小写字母各2/5
import random
def generate_code(code_len = 6):
all_nums = '0123456789'
all_a = 'abcdefghijklmnopqrstuvwxyz'
all_A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
code = ''
for i in range(0,code_len):
num = random.randint(1,6)
if(num == 1):
index = random.randint(0, len(all_nums)-1)
code += all_nums[index] #数字
elif(num == 2 or num == 3):
index = random.randint(0, len(all_a)-1)
code +&