Python Show-Me-the-Code 0,001st question generation activation Code, pythoncode

Source: Internet
Author: User

Python Show-Me-the-Code 0,001st question generation activation Code, pythoncode

Question 0,001st:As an independent developer of the Apple Store App, you need to perform a limited-time promotion for your AppGenerate activation code(Or coupons). How can I generate 200 activation codes (or coupons) using Python )?

I don't know how to generate the activation code, so it is more reliable. Therefore, it is a random combination of letters and numbers. Please let me know if there is a better way :)

The generated is probably like this:

0001. Generate the activation code. py

#! /Usr/bin/env python # coding: utf-8import string, random # characters and numbers in the activation code field = string. letters + string. digits # obtain a random combination of four letters and numbers def getRandom (): return "". join (random. sample (field, 4) # The number of def concatenate (group): return "-" In each generated activation code "-". join ([getRandom () for I in range (group)]) # generate n group activation code def generate (n): return [concatenate (4) for I in range (n)] if _ name _ = '_ main _': print generate (200)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.