Python 练习册,每天一个小程序(1)

来源:互联网 发布:lm358数据手册 编辑:程序博客网 时间:2024/05/06 14:53

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

python uuid 文档

def generateCode():    import uuid    f = open("code.txt", "w")    codeset = set()    i = 0    while True:        code = uuid.uuid4()        if code not in codeset:            codeset.add(code)            i += 1            f.write("%d. %s\n" % (i, code))        if i >= 200:            break    f.close()
0 0
原创粉丝点击