python题:随机密码生成。编写程序,在26个字母大小写和9个数字组成的列表中随机生成10个8位密码
keep_words=['and','as','assert','break','class','continue',
'def','del','elif','else','except','finally',
'for','from','global','if','import','in','is',
'lambda','nonlocal','not','or','pass','raise',
'return','try','while','time','with','yield','True',
'False','None']
def upper_word(fname_tem,num,keep):
file_tem=open('{}.py'.format(format(fname_tem)),'r',encoding='utf-8')
file_new=open('{}_changed.py'.format(format(fname_tem)),'w',encoding='utf-8')
#逐行读取,逐行处理,逐行写入
for line in file_tem:
for word in keep_words:
if word in line:
num=num+1
keep['编号%s'%str(num)]=word
line=line.replace(word,'编号%s'%str(num))
else:
continue
line=line.upper()
for key in keep.keys():
if key in line:
line=line.replace(key,keep[key])
file_new.write(line)
file_tem.close()
file_new.close()
def main():
num=100
keep={}
fname_tem=input('请输入Python源代码文件名:')
upper_word(fname_tem,num,keep)
main()
扩展资料:
定义和用法
<input>标签用于搜集用户信息。
根据不同的type属性值,输入字段拥有很多种形式。输入字段可以是文本字段、复选框、掩码后的文本控件、单选按钮、按钮等等。
input()函数直接接受且不改变输入数据的类型,但是需要注意的是使用input()在输入字符串时需要添加引号,否则会报错。
<2>.end=''标明在end后面传递一个空字符串,这样print函数不会在字符串末尾添加一个换行符,而是添加一个空字符串,也就是说,它的意思是末尾不换行,加空格。
HTML与XHTML之间的差异
在HTML中,<input>标签没有结束标签。
在XHTML中,<input>标签必须被正确地关闭。
2024-07-18 广告
import random
s =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z", "0","1","2","3","4","5","6","7","8","9"]
#方法1:
for i in range(10): #循环10遍,生成10组密码
for i in range(8): #单次随机取一个,循环8次
print (random.choice(s),end="") #random.choice(seq)实现从序列或集合seq中随机选取一个元素
print("\n") #每输出一组后,换行输出下一组
#方法2:
for i in range(10): #循环10遍,生成10组密码
k = random.sample(s,8) #random.sample(seq, k)实现从序列或集合seq中随机选取k个独立的的元素,以列表形式输出
for i in k: #遍历随机数组中的每一项并输出
print(i,end="")
print("\n") #每输出一组后,换行输出下一组
src_digit = string.digits
src_uppercase = string.ascii_uppercase
src_lowercase = string.ascii_lowercase
lis = []
for j in range(10):
for i in range(8):
digit = random.randint(1, 8)
if digit == 8:
uppercase = 0
lowercase = 0
continue
uppercase = random.randint(1, 8 - digit)
if uppercase + digit == 8:
lowercase = 0
continue
lowercase = 8 - digit - uppercase
password = random.sample(src_digit, digit) + random.sample(src_uppercase, uppercase) + random.sample(src_lowercase, lowercase)
random.shuffle(password)
new_password = ''.join(password)
if new_password not in lis:
lis.append(new_password)
print(lis)
strs=[]
for i in (65,97):
for j in range (26):
stars +=chr(I+j)
for I in range(10):
stars += str(i)
for i in range(10):
print(“密码”,i +1,”:”,end =‘’)
for j in rang(8):
print(strs[random.randint(0,61)],end =‘’)
print ()