qiyiguo

导航

 
# 1、作业:
# 1、写一个函数,函数的功能是生成一批密码,存到文件里面
# 1、def gen_password(num):
# #num 代表生成多少条密码
# pass
# 2、密码复杂度要求
# 1、长度在,8-16位之间
# 2、密码必须包括大写字母、小写字母、数字、特殊字符
# 3、密码不能重复
# 3、生成的密码保存到文件里
# 2、写一个函数,函数的功能是生成一批双色球号码
# def gen_seq(num):
# pass
# 1、中奖号码由6个红色球号码和1个蓝色球号码组成
# 红球的范围是:1-33
# 蓝球的范围是:1-16
# 2、产生的不能重复
# 蓝球:05 红球:01 03 05 17 18 32
# 蓝球:05 红球:01 03 05 17 18 32
# 蓝球:05 红球:01 03 05 17 18 32

# import random,string
# def passwd_build():
# content = set(string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation)# 小写、大写、数字、特殊字符的集合
# n = random.randint(8, 16)# 生成8-16
# passwd = random.sample(content, n)# 从content中随机取8-16位
# passwd = set(passwd)#转换为集合
# if not passwd.isdisjoint(set(string.ascii_lowercase)) and not passwd.isdisjoint(set(string.ascii_uppercase)) and \
# not passwd.isdisjoint(set(string.digits)) and not passwd.isdisjoint(set(string.punctuation)):#生成的集合 要与 小写集合/大写集合/数字集合/特殊字符集合 都有交集
# password=''.join(passwd)#集合转为字符串
# return password
# return passwd_build()
# def gen_password(num):
# num=int(num)
# for i in range(num):
# with open('passwords.txt','a+',encoding='utf-8') as f:
# f.seek(0)
# password=passwd_build()
# if password in f:
# num-=1
# else:
# f.write(password + '\n')
# m=input('请输入密码生成条数:')
# gen_password(m)

#双色球
import random
def ball_build():
l = []
n = str(random.randint(1, 16))
n = n.zfill(2)
l.append(n)
for i in range(6):
m = str(random.randint(1, 33))
m = m.zfill(2)
l.append(m)
ball = ' '.join(l)
return ball
def gen_seq(num):
num = int(num)
for i in range(num):
with open('balls.txt','a+',encoding='utf-8') as f:
f.seek(0)
ball=ball_build()
if ball in f:
num-=1
else:
f.write(ball+'\n')
print('添加成功')
count=input('请输入双色球生成条数:')
gen_seq(count)
posted on 2018-09-10 13:00  qiyiguo  阅读(1362)  评论(0)    收藏  举报