Password generator not working

110 Views Asked by At

I am a python noob and I don't know what's wrong with my code. Whenever I run it it just prints out "this is your password: " with nothing after that when it is supposed to print out the generated 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)

Any help would be great. I don't know where I went wrong. Thank you!

1

There are 1 best solutions below

2
On BEST ANSWER

You didn't change the value of 'choice' with your return statement after your While loop.

I did a few modifications.

There you go :

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