-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmk_passwd.py
More file actions
23 lines (19 loc) · 753 Bytes
/
mk_passwd.py
File metadata and controls
23 lines (19 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import random
import pytest
def mk_passwd(satz, min_words = 8, add_random_numbers = True):
words = satz.split()
if len(words) < min_words:
raise ValueError('Too few words')
pwd = ''
for word in words:
pwd += word[0]
if add_random_numbers:
pwd += str(random.randint(0,9))
if add_random_numbers:
return pwd[:-1]
else:
return pwd
def test():
assert mk_passwd("We have found out that you are using a non-english keyboard layout", min_words=11, add_random_numbers=False) == 'Whfotyauankl'
with pytest.raises(ValueError):
mk_passwd("We have found out that you are using a non-english keyboard layout", min_words=13, add_random_numbers=False)