发布时间:2019-06-30 15:27:19编辑:auto阅读(1824)
做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成200个激活码(或者优惠券),并将生成的激活码(或者优惠券)保存到 MySQL 关系型数据库中。
def getrand():
while True:
a=random.randint(48,122)
if a<=57 or (a>=65 and a<=90) or (a>=97 and a<=122):
break
return a
if __name__=='__main__':
import random
import pymysql
array=[]
for k in range (200):
rand=''
for i in range(6):
rand=rand+chr(getrand())
array.append(rand)
conn=pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='',db='mysql')
cur=conn.cursor()
cur.execute('create table if not exists juan (ma varchar(20))')
cur.executemany("insert into juan values(%s)",array)
cur.close()
conn.commit()
conn.close()使用的是python3.5版本的。。。
上一篇: 【Python】07、python内置数
下一篇: python购物车功能实现
51316
50768
41363
38169
32651
29541
28386
23259
23229
21554
1629°
2363°
1967°
1910°
2240°
1947°
2640°
4426°
4266°
3037°