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)