python小练习②

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python小练习②相关的知识,希望对你有一定的参考价值。

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

#coning=utf-8
import random
import string
def gene_activation_code(number,length):
    result={}
    source = list(string.ascii_uppercase)
    for index in range(0,200):
        source.append(str(index))
    while len(result)<number:
        key = ‘‘
        for index in range(length):
            key += random.choice(source)
        if key in result:
            pass
        else:
            result[key] = 1
    for key in result:
        print key
if __name__ == "__main__":
    number = 200
    length = 16
    gene_activation_code(number,length)

实验部分效果:

技术分享

 

以上是关于python小练习②的主要内容,如果未能解决你的问题,请参考以下文章

小片段中的 ORA-06512 [重复]

Python小练习更改版(更改一部分代码,与错误)

Python小练习更改版(更改一部分代码,与错误)

python小练习

python小练习简单的猜数字游戏

Python 练习冊,每天一个小程序