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
優秀!非常感謝!我知道有一種更好的方法,然後重複一遍又一遍的單行代碼。 –