question No. 0001: as an independent developer of the Apple Store App, do you want to make a limited-time promotion, generate an Activation code (or coupon) for your app, and use Python to generate 200 activation codes (or coupons)?
Do not know what method to generate the activation code is more reliable, so the letter and the number of the random combination. If there is a better way please tell me:)
The generated is probably the same:
0001. Generate the Activation code. PY
#!/usr/bin/env python#coding: Utf-8ImportString, random#激活码中的字符和数字field = String.letters + string.digits#获得四个字母和数字的随机组合 def getrandom(): return "". Join (Random.sample (field,4))#生成的每个激活码中有几组 def concatenate(group): return "-". Join ([Getrandom () forIinchRange (group)])#生成n组激活码 def generate(n): return[Concatenate (4) forIinchRange (n)]if__name__ = =' __main__ ':PrintGenerate $)
Python show-me-the-code No. 0001 generate activation Code