Skip to content

Commit d87ae90

Browse files
authored
Fixed password.py
Fixed password.py to raise ValueError when password length is shorter than required characters
1 parent 9cd0adb commit d87ae90

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

‎other/password.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,31 @@ def password_generator(length: int = 8) -> str:
2626
# chars_incl= characters that must be in password
2727
# i= how many letters or characters the password length will be
2828
def alternative_password_generator(chars_incl: str, i: int) -> str:
29+
"""
30+
Generate a password that includes the required characters and has a total length of i.
31+
>>> len(alternative_password_generator("abcdefgh", 8))
32+
8
33+
>>> len(alternative_password_generator("abcdefgh", 5))
34+
Traceback (most recent call last):
35+
...
36+
ValueError: Requested length must be at least the number of required characters.
37+
>>> len(alternative_password_generator("abc", 3))
38+
3
39+
"""
2940
# Password Generator = full boot with random_number, random_letters, and
3041
# random_character FUNCTIONS
3142
# Put your code here...
43+
# chars = chars_incl + random_letters(ascii_letters, i / 3 + remainder) +
44+
# random_number(digits, i / 3) + random_characters(punctuation, i / 3)
45+
if i < len(chars_incl):
46+
raise ValueError(
47+
"Requested length must be at least the number of required characters."
48+
)
49+
3250
i -= len(chars_incl)
3351
quotient = i // 3
3452
remainder = i % 3
35-
# chars = chars_incl + random_letters(ascii_letters, i / 3 + remainder) +
36-
# random_number(digits, i / 3) + random_characters(punctuation, i / 3)
53+
3754
chars = (
3855
chars_incl
3956
+ random(ascii_letters, quotient + remainder)

0 commit comments

Comments
 (0)