Python appending list -
trying change list can generate password
passwordlength=int(input('enter how long password')) # user input x in range(0,passwordlength): password=''.join(characters) print(password)
that working now. characters using list. giving me input list repeated input number.
every time try , use append list end going backwards
any appreciated
i think random.sample may want:
from random import sample passwordlength = int(input('enter how long password')) # user input password = ''.join(sample(characters,passwordlength))
or else take slice passwordlength
:
password = ''.join(characters[:passwordlength])
to validate user input can use try/except , while loop:
from random import sample while true: try: password_length = int(input('enter password length between 1-{}'.format(len(characters)))) # user input if password_length > len(characters): print("password long") continue password = ' '.join(sample(characters,password_length)) break except valueerror: print("please enter digits only")
if have ints in character list need map
str
before joining.
password = ' '.join(map(str,sample(characters,password_length)))
Comments
Post a Comment