【问题标题】:Pycharm shows no problems but wont give any outputPycharm 显示没有问题,但不会给出任何输出
【发布时间】: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) &lt; length:。您当前正在将密码本身与length 进行比较。但是,字符串永远不会等于数字。

标签: python python-3.x string


【解决方案1】:
while i < amount:
    password = ""
    while len(password) != length:
        password_char = random.choice(Possible_chars)
        password = password + password_char
    print(password)
    i += 1

【讨论】:

    猜你喜欢
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2023-03-03
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多