您的位置:首页 > 编程语言 > Python开发

Python练习册,第 0001 题

2018-04-09 16:40 302 查看
第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?

import random
import string

codesnumber = 200
codeslength = 12

def makeACode( length ):
codes = '';
for i in range(length) :
codes += random.choice(string.ascii_letters + string.digits)
return codes;

def makeCodes( numbers, length ):
codesset = [];
for i in range(numbers):
codesset.append(makeACode(length))
return codesset

print makeCodes(codesnumber, codeslength)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息