密码生成器不起作用



我是一个python菜鸟,我不知道我的代码出了什么问题。每当我运行它时,它只会打印出"这是您的密码:",之后没有任何内容,当它应该打印出生成的密码时。

import random
strength = ['Weak', 'Medium', 'Strong']
charbank = ('1234567890qwertyuiopASDFGHJKLZXCVBNM')
chosenchars = ('')
choice = ('')
def inputfunction():
    while True:
        userchoice = input("Would you like your password to be: n Weak n Medium? n Strong?n")
        if userchoice in strength:
            choice = ''.join(userchoice)
            break
        print ('oops, that's not one of the options. Enter again...')
    return choice
def strengththing():
    if choice == ("Weak"):
        Weak()
    if choice == ("Medium"):
        Medium()
    if choice == ("Strong"):
        Strong()
def Weak():
    passlen = 5
    chosenchars.join(random.sample(charbank, passlen))
def Medium():
    passlen = 10
    chosenchars.join(random.sample(charbank, passlen))
def Strong():
    passlen = 15
    chosenchars.join(random.sample(charbank, passlen))

inputfunction()
strengththing()
print ('this is your password: %s' %chosenchars)

任何帮助都会很棒。我不知道我哪里做错了。谢谢!

在 While 循环之后,您没有使用 return 语句更改"选择"的值。

我做了一些修改。

给你:

#!/usr/bin/env python3
import random
strength = ['Weak', 'Medium', 'Strong']
charbank = ('1234567890qwertyuiopASDFGHJKLZXCVBNM')
chosenchars = ('')
choice = ('')
def inputfunction():
    while True:
        userchoice = input("Would you like your password to be: n Weak n Medium? n Strong?n")
        if userchoice in strength:
            choice = ''.join(userchoice)
            break
        else:
            print ('oops, that's not one of the options. Enter again...')
    return choice
def strengththing():
    if choice == 'Weak':
        return RandomPass(5)
    if choice == 'Medium':
        return RandomPass(10)
    if choice == 'Strong':
        return RandomPass(15)
def RandomPass(passlen):
    myVar = ''.join(random.sample(charbank, passlen))
    return myVar
choice = inputfunction()
chosenchars = strengththing()
print ('this is your password: %s' %chosenchars)

相关内容

  • 没有找到相关文章