import random
import string
oneFile = open('password.txt', 'w')
userInput = 0
key_count = 0
key = []
chars = string.ascii_uppercase + string.digits + string.ascii_lowercase
for userInput in range(int(input('How many keys needed?'))):
while key_count <= userInput:
number = random.randint(1, 999)
if number not in key:
key_count += 1
key.append(number)
text = str(number) + ": " + str(''.join(random.sample(chars*6, 16)))
oneFile.write(text + "\n")
oneFile.close()
print("Data written, please Rename or it will be over written.")
raw_input("press enter to exit")
我如何得到它让出来放看起来是这样的:
955:PFtKg-r1fd1-g9FX23与字符的选择量后的破折号之间?如何在输出之间自动添加破折号?
text = str(number) + ": " + str(''.join(random.sample(chars*6, 16)))
#puts everything together but i would have to repeat
# + str(''.join(random.sample(chars*6, 16))) on the line in code
优秀!非常感谢!我知道有一种更好的方法,然后重复一遍又一遍的单行代码。 –