Random Password Generator

I came across this tutorial for building a random password generator. It seemed simple enough and it was. The original code was only about twenty lines I believe. However, since I don’t like just copying and pasting code and I like to make my stuff more complete, I decided to add in a few things that I learned from another tutorial (a console-based python slot machine) and added in some error checking. Also, since I’m a firm believer in object-oriented programming, I broke it out into functions and just called the functions at the end.

I did notice a couple of unimportant things I had to change because of the way trinket.io handles python. I don’t think they’re using the latest version as it can’t handle “f-strings”. When I coded this in VS Code on my laptop, I used f-strings since it makes it easy to output variable data with strings without super long concatenated strings. However, the compiler built into the trinket.io website didn’t like that and wouldn’t run the code. I’ll post the original code below

import random

MAX_PWDS = 10
MIN_PWDS = 1
MAX_PWD_LENGTH = 10
MIN_PWD_LENGTH = 4
NUM_PWDS = 0
PWD_LENGTH = 0

print("Welcome to the password Generator")

chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*().,;:'

#Gather number of passwords
def numPWDS():
    while True:
        number = input(f"Number of passwords to generate ({MIN_PWDS}-{MAX_PWDS}): ")
        if number.isdigit():
            number = int(number)
            if MIN_PWDS <= number <= MAX_PWDS:
                return(number)
            else:
                print("Please try again.")
        else:
            print("Please enter a number value")

#Gather password Length
def pwdLength():
    while True:
        length = input(f"Length of password(s) ({MIN_PWD_LENGTH}-{MAX_PWD_LENGTH}): ")
        if length.isdigit():
            length = int(length)
            if MIN_PWD_LENGTH <= length <= MAX_PWD_LENGTH:
                return(length)
            else:
                print("Please try again.")
        else:
            print("Please enter a number value")


#Print results
def printPWDS():
    print("Here are your passwords:")
    for _ in range(NUM_PWDS):
        password = ""
        for _ in range(PWD_LENGTH):
            password += random.choice(chars)
        print (password)

#Call and run programs
NUM_PWDS = numPWDS()
PWD_LENGTH = pwdLength()
printPWDS()