【发布时间】:2021-09-02 23:53:40
【问题描述】:
我正在尝试制作一个脚本,该脚本接受输入和长度并生成随机密码,但是问题是什么都没有出现。 “第 29 行,在 密码 = 密码 + 密码字符 键盘中断” 我不得不自己停止它,因为即使几分钟后它也不会输出或停止自己
Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Lowercase = "abcdefghijklmnopqrstuvwxyz"
Numbers = "0123456789"
Symbols = "!@#$%^&*"
length = int(input("how long would you like your password? : "))
amount = int(input("how many passwords would you like? : "))
Possible_chars = ""
Q_Uppercase = input("Would you like uppercase characters in your password? : ").lower()
if Q_Uppercase == "yes":
Possible_chars += Uppercase
Q_Lowercase = input("Would you like lowercase characters in your password? : ").lower()
if Q_Lowercase == "yes":
Possible_chars += Lowercase
Q_Numbers = input("Would you like numbers in your password? : ").lower()
if Q_Numbers == "yes":
Possible_chars += Numbers
Q_Symbols = input("Would you like symbols in your password? : ").lower()
if Q_Symbols == "yes":
Possible_chars += Symbols
i = 0
while i < amount:
password = ""
while password != length:
password_char = random.choice(Possible_chars)
password = password + password_char
print(password)
i += 1
【问题讨论】:
-
你的意思是
while len(password) != length:,或者while len(password) < length:。您当前正在将密码本身与length进行比较。但是,字符串永远不会等于数字。
标签: python python-3.x string