如何使用Python生成200个优惠券(激活码) - 星辰虎贲

时间:2024-03-08 16:45:53

如何使用Python生成200个优惠券(激活码)

解析:

常见的优惠券(激活码)是由数字、字母(大小写)组成;

string.ascii_letters   26个大小写字母;

string.digits 0-9数字;

随机组合 使用random.sample

import random
import string


code = string.ascii_letters + string.digits
print(code)

#获取随机生成的4位字符串
def getCode():
return "".join(random.sample(code, 4))
print(getCode())


#获取4列4位激活码 以"—"串联起来
def key(group):
return "—".join([getCode() for i in range(group)])
print(key(4))


#获取200组激活码 每组4列4位
def keys(n):
return "\n".join([key(4) for i in range(n)])

print(keys(200))

 

E:\Python37\python.exe E:/PythonTest/Test0625/Test001.py
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
Bai5
Ebmy—qBY2—J7ic—6uV3
vVQ2—KCXx—YHzn—snPg
wdHD—b8nC—1ru8—ckBv
WRmh—4Ka8—2ISy—vN0W
r6Vv—IJA6—RIp2—ErDM
s7Wk—zxfh—poWL—dgoP
2PvJ—dCPE—UaI9—rhlv
kA8u—Rvy0—ztex—4i3P
ideD—o13n—IpTJ—bEsa
JT6k—Ym13—QsAj—3DxC
6JZw—1LDH—9uNb—EV6h
lrKx—0ZUM—hjvX—KRX8
ZCxF—5hpt—jIQb—yJZo
ApLb—k8mf—vpTW—HKT2
FZjz—A9os—tNaw—69fe
9Xu3—kpzd—VZJ6—yuF5
ploH—P7cp—y2lx—tMuo
OzBe—UEQq—s0DW—kP3x
SfcY—X2af—runG—qTug
ijcm—EbNB—jPI4—N8pu
lKCg—WP6q—SIDm—hlua
5Bo7—HS47—qT8w—1stT
3wJn—0A5o—lF17—5i0L
PAf5—2OGF—uk4j—Mkud
csBV—BPVF—Ypzo—bgDx
ZOWa—KVZE—u4Lm—eZOu
xqJ0—j5ng—ZPwB—16Cz
OqQR—SLmG—NIkn—4AbN
Wxt9—mGIe—iyJb—68jX
hOAd—REKD—fmDw—ab36
6MrN—tlew—LKfE—0Po7
BZPS—TzYi—xhfp—Bybv
e8Mn—qpdL—NZ3d—pBsy
TNmV—nkob—Uv9i—F93m
DaBF—2xeQ—muxE—Z85l
oBFN—Qq5l—SyC1—f3Oe
8Fu0—F0CI—dma6—6wWr
5K9p—2r7j—LuKM—Qx3A
dFvu—rRiB—EO6J—HUrL
duez—TnNL—IVTc—hwkA
ne9A—8BSe—nOHm—YU6X
rEc1—z96S—IahM—GLJ3
YP1g—Clsy—53EY—BTFa
ZBTH—Ss3D—wo43—XGea
t1Vc—NDkL—4AF9—wTFA
Svk0—2h0v—QJbg—yUIC
9aYn—OrUk—LFwZ—wyl8
N3O6—yVEG—LcHV—Y91y
xF7Z—Apoa—5KXv—HD2e
U4EQ—3CXL—GQKg—KpX3
dfls—AmdC—a3HO—hXeg
3v7s—f67L—Yuwi—1Bdb
pCkP—nZoA—Y0rG—zyid
zumh—MeGW—ruRM—xr7o
6UAb—DES6—ACGY—Lvnx
OoAy—TRgl—ncsC—XS29
Z4n1—fjcB—8RSg—g39J
7A9M—5EgB—V80H—L61F
3iQq—kNVc—pts6—1Eve
VItc—b9Gg—WH4Q—243X
6ger—RdHx—kNMX—NR3K
T01F—irZM—r4M5—VlxK
crRG—C3FG—eqUP—BXRH
2DH4—kd5O—ywok—Z82X
iMjP—EByU—myUb—l89F
1Iqn—nGX6—ZdLv—nKph
cTqo—bQSF—gMhE—o9pG
T1YK—ivzS—YKlA—hPf1
A7IT—Jsg2—3HFL—7aD5
URyD—0cW4—IyWP—aGzV
Gktr—vSiM—YnLr—K0Fq
z3fD—TWKz—l7Zc—wB0v
BYvE—yjR9—CLDy—7m26
15Xi—jdBI—elx5—YagK
iUs8—nX5K—6Qwb—kH4q
vOUm—ykX5—Xvs0—CJba
ZtIH—34JK—Tljz—id1c
afhm—zey1—fARn—AC5r
gPEU—OFYk—zpTf—7wJk
jxHn—s1mc—0AbX—wvl4
MVTC—TJAl—GYAC—J0gK
qTiP—jhfK—36Qe—ZdfS
GqES—n6zu—NzVl—tVsm
wPfI—qbtg—q8s2—G1VK
04cE—bvyL—PvH5—sba6
ejT0—5YgF—ZRYL—ID13
iCsr—DAjT—iIVa—ny92
KAJe—QOh2—bOZA—BYVH
Q5X9—SewW—RKbm—dj4X
jd03—o8rw—wyz7—xW1s
Fdc5—I3dN—7isy—Phni
faWh—jnb3—K0A3—Gy6e
nzoI—rf19—qW7C—5Rfw
hKnb—xsRa—AmPN—sZBJ
LqUy—6Fx0—1eIw—ldJI
SvxP—2aFk—JUpG—3xJQ
pZ7y—P7Uw—Z35z—xecs
yHzK—Wx9B—5Vk2—YzVl
Kpt2—oQUb—Nw3P—R4lq
slhX—GU2T—c1iw—8KyC
hx5T—aGOn—joLz—AoZE
l9Ri—MRbQ—iln0—VWd3
rdPK—YsU7—CWZ7—Co3A
zaAg—aHJI—fi8W—Eni7
THBl—LdKO—he1m—nxgG
AWkC—cZ17—NmRs—kU5o
SPCH—413x—xJa4—qO5z
ol4G—GQBO—1cmu—R7jd
Cx3e—P4gb—XHTc—L8uT
WN7v—hNce—7YrA—8d4w
WIA7—WI23—FEz2—3enA
IoWz—VdRh—yHRG—eHhm
rLKD—rz3d—Y8qj—cfAG
B5pu—t3Fa—gZAG—W5Y7
bOrR—JxAI—jhz6—Ks7m
QqGp—DMmN—mUXM—KDWG
RtoL—pLWY—R8kP—yTHW
YI9v—Zs43—A2pG—QEYh
CeVw—LMrq—kw1b—uD8R
rNux—NKgL—5mhQ—zYR9
8dL7—qvna—YqhA—ZkuA
f8KT—HwfL—0JwM—e8Tf
27zW—9XSL—fzMO—5adU
lfSr—qFdN—7PMi—BJ0g
91IJ—pyj6—1mJn—6ibl
6ei1—Y7Nb—PpBF—W9eL
ZWNX—zdlh—6FNr—4Yrv
weDI—EUn4—qMZ4—zs1P
kyZb—mT94—NgRO—6Uk8
qJH9—fVry—PiAY—Q6UZ
nM2T—yWDJ—0qZw—RlUP
5yRw—PjUD—7zYN—GQFc
p8dl—I9eM—p1eZ—nrgd
l8ht—F2HY—FU0g—dlnx
kXxf—SIBp—840q—cDTF
eYOF—Z5c4—M2Tc—GJnc
4Omc—OCuG—vIjW—OvW4
p8x4—fUxQ—iu3O—yu6J
D7qI—l69t—X0a9—DML0
f5oD—TIv2—UtyS—9zku
LqoJ—fv9a—UFRJ—vkSp
cZtl—5jm9—vj05—vVd2
wuxa—Iket—LnOJ—XQpn
Ke3n—uSyz—Lltb—cdza
FyAz—k9aH—3BG5—rbfB
jfCy—cpQ5—zQ2H—Cmuy
ZTL9—B1br—W0rB—AHrL
PrcL—PisE—y2DN—J3jc
6YE8—9IGP—ygsE—BJ0w
wctJ—m6eN—klpy—v9xI
zGvn—iADI—vZVL—RHNs
QveF—H3F5—pcMV—2RaA
RqV7—2U3Y—Dj1H—pha5
dcWh—CGFy—suGQ—fbwy
woTV—Ymoq—7c84—r4it
RrZD—PTmn—FRmU—Ensw
YGfH—TcW2—iPNg—Azgp
l4QR—WeaR—S5jC—bdxT
Mzsr—Xvu2—XMj9—sldk
Z7YG—Ih0o—rj1g—DpHb
SgkH—DMY9—OXcr—zH5C
bfe1—GQjm—j7u4—yl8n
uF2Q—sl9L—YmU2—D2bZ
Dtw6—B8eP—eSAq—Ady8
9a1l—qWhf—82hc—kjfM
ZnVG—ZFgp—SGob—UGBr
YkVi—hwU0—3TNl—wpdC
7EaC—VpRO—QJT0—fk1Z
oPwa—En9t—ZvyX—7ByH
KQ6o—BOpx—TStv—2ocZ
Ymp0—1Kj3—uXt7—C7jm
XCvS—xSm2—jE2c—78Mv
sAOU—kDGO—EzWm—Gu0k
ZXb6—i2jo—GrbA—DMKY
4esw—nhJK—C3WZ—0gcI
oivq—mUBA—yW1r—8M5W
ew4W—yzbi—4bQ5—muAv
MyzJ—3Qlw—aHul—mH8W
gt0W—jdoH—Ul6c—NKw2
to7h—qjQk—UxTO—1hlr
kIjU—qE7D—aVxM—lTkB
N0Ss—r160—86BV—s9r2
b6Jn—im02—fRLo—qr0s
uqQ7—DfAn—MseE—whP6
XACd—umqx—Hynm—KU5s
C21K—J6lX—eqwj—JwlU
CY3c—xSyg—VyBE—6vNu
uFCL—RvO7—4tNP—7SsF
uyDq—VYtR—Q98W—Fxm2
g2mt—Ovzo—k2Sc—XAZL
stAa—lsnh—0opw—gF8r
Y3Kx—4W82—1dYM—7DIY
1dET—wvQs—6Sef—j4U1
4fNZ—9GT7—9gzA—1bRA
6l5d—mLtH—jI4B—ca0G
8upQ—OUyE—YKuC—d4Sh
GpPT—uZNj—nlpa—NuXr
asBj—cCd9—su5O—W0LX
LlE0—Z79v—1xub—lyrR
4fbj—cfVq—iNcV—M9A2
eWrv—klN9—6nh1—OZUK

Process finished with exit code 0