0

After running, and choosing password strength, there is nothing stored in "password". Also, is there a way to avoid making 5 if loops for each password_strength level?

import string
import random

def password_generator() :
    password_strength = [1,2,3,4,5]
    password = []
    user_choice = input("Enter desired password strength (1-5) : ")

    if user_choice == password_strength[0] :
        password_length = 4
        for i in range(0, password_length) : 
            password.append(chr(random.randint(33,126)))

    print(password)

password_generator()
Apollo
  • 118
  • 1
  • 9
  • Use a dict to map `password_strength` to `password_length`: `password_length = {1: 4, 2: ...}[user_choice]`. And in the future, please avoid asking multiple questions in a single question. – Aran-Fey May 25 '18 at 05:45
  • Thanks for the tip. – Apollo May 25 '18 at 05:46

1 Answers1

0

This is the faulty line, cast your input to integer.

user_choice = int(input("Enter desired password strength (1-5) : "))
BcK
  • 2,548
  • 1
  • 13
  • 27