#e6.1随机密码生成,在26个字母大小写和9个数字组成的列表中随机生成10个8位密码
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):
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") #每输出一组后,换行输出下一组