Password Generator
Easy
4
45.2% Acceptance
In this lab, you will create a Python function named generate_password
. This function is designed to generate strong, random passwords based on specified criteria. The password will consist of a mix of letters, numbers, and symbols. You need to ensure that the counts of each character type (letters, numbers, symbols) are taken as parameters, with default values of 2 for each and length parameter with the default value of 6.
Function Requirements:
- The function should be named
generate_password
. - It should take four parameters:
length
(total length of the password),letters_count
,numbers_count
, andsymbols_count
. - If
letters_count
,numbers_count
, orsymbols_count
are not specified, they should default to 2. - The function should return a randomly generated password string with the specified mix of characters.
- The function should raise an
ValueError
in the length passed is less than the sum ofletters
,numbers
andsymbols
together
Examples:
-
Example 1:
- Input:
generate_password(length=8, letters_count=3, numbers_count=3, symbols_count=2)
- Output: A random password of 8 characters, with 3 letters, 3 numbers, and 2 symbols. Example:
a2#b4c5?
- Input:
-
Example 2:
- Input:
generate_password()
- Output: A random password of 6 characters, using the default count of 2 for letters, numbers, and symbols. Example:
1d$2e#
- Input:
-
Example 3:
- Input:
generate_password(length=6, letters_count=3, numbers_count=3, symbols_count=2)
- Output:
ValueError
- Input:
Remember to test your function thoroughly to ensure it meets the criteria specified in the challenges. Good luck!
TIP: You can make use of
random
andstring
modules to write the function easily