每天一python 题 0001

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

import random,string



def get_coupon(nums,lens):
    # nums:生成总数
    # lens:激活码长度
    for x in range(nums):
        coupon=random.sample(sam,lens)
        coupon="".join(coupon) #合并
        print(coupon)
        write_in_file.writelines([coupon +'\n'])


if __name__=="__main__":
    write_in_file = open("ex0003.txt", "w")
    sam = string.ascii_letters + string.digits
    get_coupon(200,20)
    write_in_file.close()
重新写入了文件~#有关合并还有一个方法:http://hw1287789687.iteye.com/blog/2253173




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值