所以为了使用我新学的python,我编写了一个随机密码的小工具。你知道吗
最终我得到了一个列表,比如说15个字符串。我要求用户输入他想要的密码数和密码长度。-相反,我想问他最小和最大长度是多少,而不是一个集合长度,并在我的结果中得到完整的范围。你知道吗
到目前为止,我的情况是:
items = ['5', '4', 'Y', 'T', 'R', 'E', 'h', 'g', 'f', 'd', '7', '1', '9', 'z', 'q', 'x']
x=int(raw_input("how many passwords would you like?:"))
z=int(raw_input("how long would you like the password to be?:"))
print("the list of possible passwords you received is:")
for i in range (x):
random.shuffle(items)
输出结果如下:
TR1Eg47f9
5gRf9q7Ed
hxfE5gR4d
hE14x9Tz7
谢谢你。你知道吗
使用random.sample可以从列表中获得特定数量的项。你可以这样做:
问题是
x
不能大于项目长度。您可以先进行一些修复,重复列表中的项目,如下所示:相关问题 更多 >
编程相关推荐