question No. 0001: as an independent developer of the Apple Store App, do you want to make a limited-time promotion, generate an Activation code (or coupon) for your app, and use Python to generate 200 activation codes (or coupons)?
#coding = Utf-8__author__='Liez'ImportRandomdefmake_number (num, length): Str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'a=[] I=0 whileI <Num:numstr="' forJinchRange (length): Numstr+=random.choice (str)ifNumstr not inchA:#if not repeateda.append (numstr) I+ = 1Print(NUMSTR) Make_number (20,10)
Note
random.choice(seq): Return a random element from the non-empty sequence seq. If seq is empty,
There are 20 of them, Sir:
COSSX9UMWF
qkmsbdvj0g
Ardycodyaf
F8H0DRSHJL
E0t6lf6ao1
ZB06XALSNF
SMCAQXYHQM
209ME2LSCL
NNVMMEMGQD
fqxlzvlzpc
dj7luhi53s
rytnv7yhth
Bg7pdfmge1
I7r7s1mpwk
Agn2pyf3ti
523YX6TDS8
Gmffcmyoyx
Mmzz2phieo
GAHTMOVPDT
6RGB3V2TJP
Ps:
1. I use the random module, but also see other people a lot of different practices. For example, the UUID module,uuid-universally unique identifier (universal unique identification code).
It's not clear what the difference between these sequence generation functions is (is it safer or something?). )。 UUID Module docs
2. I use list to put the generated serial number, also see with set : A set object is an unordered collection of distinct hashable objects. Common uses include membership testing, removing duplicates from a sequence, and computing mathematical, operations such as Intersection, Union, difference, and symmetric difference. More features. Set Types Docs
Specific changes:
defmake_number (num, length): Str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'a= set ()//. .. i=0 whileI <Num:numstr="' forJinchRange (length): Numstr+=random.choice (str)ifNumstr not incha:a|= {NUMSTR}//. .. i+ = 1Print(NUMSTR)
Exercise Books: Https://github.com/Yixiaohan/show-me-the-code
"Python Mini Practice" 0001