密码生成器不工作

Password generator not working

我是一个 python 菜鸟,我不知道我的代码有什么问题。每当我 运行 它只是打印出 "this is your password: " 之后什么都没有当它应该打印出生成的密码时。

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 语句更改 'choice' 的值。

我做了一些修改。

好了:

#!/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)