Password generator
Zee Hey, so command sent around a security memo about password hygiene and I got called out specifically. Embarrassing. Can you make a little password generator? I give it a length, say yes or no to numbers and symbols, it spits out something I can actually use. I guess using "password123" for all accounts is not the best...
What you're building
Password length: 12
Include numbers? (y/n): y
Include symbols? (y/n): y
Generated: k7#mP9xQ!2aLWhat you'll need
- Output and input — collecting the user's preferences
- Strings — characters, joining a list of characters back into a string
- Lists — building and combining the pool of allowed characters
- Modules and the standard library —
randomfor picking characters,stringfor pre-built character sets
Hints
Build the pool first. Start with an empty list of allowed characters. Add letters always, then conditionally add digits or symbols based on what the user chose.
The string module saves work. It has ready-made strings for you: string.ascii_letters, string.digits, string.punctuation. No need to type them out.
Pick, then join. Pick one character at a time using random.choice(), repeat that for the length the user asked for, then join the results into a single string.
Going further
Once the basic generator works:
- Guarantee the rules. If the user asked for numbers, make sure at least one number appears in the result. Same for symbols. Picking purely at random might miss them.
- Generate a batch. Let the user ask for multiple passwords at once and display all of them.
- Strength indicator. After generating, print a brief rating: weak (letters only), medium (letters + numbers), strong (letters + numbers + symbols).

