1def beginning(word):
2 wordLength = len(word)
3 lettersIn = 0
4 if wordLength % 3 == 0:
5 lettersIn = len(word) // 3
6 elif wordLength % 3 == 2:
7 lettersIn = len(word) // 3 + 1
8 else:
9 lettersIn = len(word) // 3
10 return word[:lettersIn]
11
12
13def middle(word):
14 wordLength = len(word)
15 lettersIn = 0
16 FromIndx = 0
17 if wordLength % 3 == 0:
18 FromIndx = wordLength // 3
19 lettersIn = len(word) // 3
20 elif wordLength % 3 == 2:
21 FromIndx = wordLength // 3 + 1
22 lettersIn = len(word) // 3
23 else:
24 FromIndx = wordLength // 3
25 lettersIn = len(word) // 3 + 1
26 return word[FromIndx : FromIndx + lettersIn]
27
28
29def end(word):
30 wordLength = len(word)
31 lettersIn = 0
32 if wordLength % 3 == 0:
33 lettersIn = len(word) // 3
34 elif wordLength % 3 == 2:
35 lettersIn = len(word) // 3 + 1
36 else:
37 lettersIn = len(word) // 3
38 return word[-lettersIn::1]
39
40
41def split_sentence(sentence):
42 words = sentence.split()
43 result = []
44 for word in words:
45 result.append((beginning(word), middle(word), end(word)))
46 return result
47
48
49print(split_sentence("казвам се Джон Сноу"))
[('ка', 'зв', 'ам'), ('с', '', 'е'), ('Д', 'жо', 'н'), ('С', 'но', 'у')]
.F....F.....
======================================================================
FAIL: test_mixed_sentence (test.TestSentence)
Test with mixed remainder input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 75, in test_mixed_sentence
self.assertEqual(split_sentence('Здравейте момчета къде ми е отвертката'),
AssertionError: Lists differ: [('Зд[50 chars], 'е'), ('м', '', 'и'), ('', 'е', 'е'), ('отв', 'ертк', 'ата')] != [('Зд[50 chars], 'е'), ('м', '', 'и'), ('', 'е', ''), ('отв', 'ертк', 'ата')]
First differing element 4:
('', 'е', 'е')
('', 'е', '')
[('Здр', 'аве', 'йте'),
('мо', 'мче', 'та'),
('к', 'ъд', 'е'),
('м', '', 'и'),
- ('', 'е', 'е'),
? -
+ ('', 'е', ''),
('отв', 'ертк', 'ата')]
======================================================================
FAIL: test_one_letter (test.TestWords)
Test with single letter.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 46, in test_one_letter
self.assertEqual(end('#'), '')
AssertionError: '#' != ''
- #
+
----------------------------------------------------------------------
Ran 12 tests in 0.001s
FAILED (failures=2)
Георги Кунчев
17.10.2023 18:15Махаме една точка, заради неспазения `snake_case`.
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
n | 2 | wordlength = len(word) | n | 2 | wordLength = len(word) |
3 | lettersIn = 0 | 3 | lettersIn = 0 | ||
n | 4 | if wordlength % 3 == 0: | n | 4 | if wordLength % 3 == 0: |
5 | lettersIn = len(word) // 3 | 5 | lettersIn = len(word) // 3 | ||
n | 6 | elif wordlength % 3 == 2: | n | 6 | elif wordLength % 3 == 2: |
7 | lettersIn = len(word) // 3 + 1 | 7 | lettersIn = len(word) // 3 + 1 | ||
8 | else: | 8 | else: | ||
9 | lettersIn = len(word) // 3 | 9 | lettersIn = len(word) // 3 | ||
10 | return word[:lettersIn] | 10 | return word[:lettersIn] | ||
11 | 11 | ||||
12 | 12 | ||||
13 | def middle(word): | 13 | def middle(word): | ||
n | 14 | wordlength = len(word) | n | 14 | wordLength = len(word) |
15 | lettersIn = 0 | 15 | lettersIn = 0 | ||
16 | FromIndx = 0 | 16 | FromIndx = 0 | ||
n | 17 | if wordlength % 3 == 0: | n | 17 | if wordLength % 3 == 0: |
18 | FromIndx = wordlength // 3 | 18 | FromIndx = wordLength // 3 | ||
19 | lettersIn = len(word) // 3 | 19 | lettersIn = len(word) // 3 | ||
n | 20 | elif wordlength % 3 == 2: | n | 20 | elif wordLength % 3 == 2: |
21 | FromIndx = wordlength // 3 + 1 | 21 | FromIndx = wordLength // 3 + 1 | ||
22 | lettersIn = len(word) // 3 | 22 | lettersIn = len(word) // 3 | ||
23 | else: | 23 | else: | ||
n | 24 | FromIndx = wordlength // 3 | n | 24 | FromIndx = wordLength // 3 |
25 | lettersIn = len(word) // 3 + 1 | 25 | lettersIn = len(word) // 3 + 1 | ||
26 | return word[FromIndx : FromIndx + lettersIn] | 26 | return word[FromIndx : FromIndx + lettersIn] | ||
27 | 27 | ||||
28 | 28 | ||||
29 | def end(word): | 29 | def end(word): | ||
n | 30 | wordlength = len(word) | n | 30 | wordLength = len(word) |
31 | lettersIn = 0 | 31 | lettersIn = 0 | ||
n | 32 | if wordlength % 3 == 0: | n | 32 | if wordLength % 3 == 0: |
33 | lettersIn = len(word) // 3 | 33 | lettersIn = len(word) // 3 | ||
t | 34 | elif wordlength % 3 == 2: | t | 34 | elif wordLength % 3 == 2: |
35 | lettersIn = len(word) // 3 + 1 | 35 | lettersIn = len(word) // 3 + 1 | ||
36 | else: | 36 | else: | ||
37 | lettersIn = len(word) // 3 | 37 | lettersIn = len(word) // 3 | ||
38 | return word[-lettersIn::1] | 38 | return word[-lettersIn::1] | ||
39 | 39 | ||||
40 | 40 | ||||
41 | def split_sentence(sentence): | 41 | def split_sentence(sentence): | ||
42 | words = sentence.split() | 42 | words = sentence.split() | ||
43 | result = [] | 43 | result = [] | ||
44 | for word in words: | 44 | for word in words: | ||
45 | result.append((beginning(word), middle(word), end(word))) | 45 | result.append((beginning(word), middle(word), end(word))) | ||
46 | return result | 46 | return result | ||
47 | 47 | ||||
48 | 48 | ||||
49 | print(split_sentence("казвам се Джон Сноу")) | 49 | print(split_sentence("казвам се Джон Сноу")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordlength = len(word) | 2 | wordlength = len(word) | ||
3 | lettersIn = 0 | 3 | lettersIn = 0 | ||
4 | if wordlength % 3 == 0: | 4 | if wordlength % 3 == 0: | ||
5 | lettersIn = len(word) // 3 | 5 | lettersIn = len(word) // 3 | ||
6 | elif wordlength % 3 == 2: | 6 | elif wordlength % 3 == 2: | ||
7 | lettersIn = len(word) // 3 + 1 | 7 | lettersIn = len(word) // 3 + 1 | ||
8 | else: | 8 | else: | ||
9 | lettersIn = len(word) // 3 | 9 | lettersIn = len(word) // 3 | ||
10 | return word[:lettersIn] | 10 | return word[:lettersIn] | ||
11 | 11 | ||||
12 | 12 | ||||
13 | def middle(word): | 13 | def middle(word): | ||
14 | wordlength = len(word) | 14 | wordlength = len(word) | ||
15 | lettersIn = 0 | 15 | lettersIn = 0 | ||
16 | FromIndx = 0 | 16 | FromIndx = 0 | ||
17 | if wordlength % 3 == 0: | 17 | if wordlength % 3 == 0: | ||
18 | FromIndx = wordlength // 3 | 18 | FromIndx = wordlength // 3 | ||
19 | lettersIn = len(word) // 3 | 19 | lettersIn = len(word) // 3 | ||
20 | elif wordlength % 3 == 2: | 20 | elif wordlength % 3 == 2: | ||
21 | FromIndx = wordlength // 3 + 1 | 21 | FromIndx = wordlength // 3 + 1 | ||
22 | lettersIn = len(word) // 3 | 22 | lettersIn = len(word) // 3 | ||
23 | else: | 23 | else: | ||
24 | FromIndx = wordlength // 3 | 24 | FromIndx = wordlength // 3 | ||
25 | lettersIn = len(word) // 3 + 1 | 25 | lettersIn = len(word) // 3 + 1 | ||
26 | return word[FromIndx : FromIndx + lettersIn] | 26 | return word[FromIndx : FromIndx + lettersIn] | ||
27 | 27 | ||||
28 | 28 | ||||
29 | def end(word): | 29 | def end(word): | ||
30 | wordlength = len(word) | 30 | wordlength = len(word) | ||
31 | lettersIn = 0 | 31 | lettersIn = 0 | ||
32 | if wordlength % 3 == 0: | 32 | if wordlength % 3 == 0: | ||
33 | lettersIn = len(word) // 3 | 33 | lettersIn = len(word) // 3 | ||
34 | elif wordlength % 3 == 2: | 34 | elif wordlength % 3 == 2: | ||
35 | lettersIn = len(word) // 3 + 1 | 35 | lettersIn = len(word) // 3 + 1 | ||
36 | else: | 36 | else: | ||
37 | lettersIn = len(word) // 3 | 37 | lettersIn = len(word) // 3 | ||
38 | return word[-lettersIn::1] | 38 | return word[-lettersIn::1] | ||
39 | 39 | ||||
40 | 40 | ||||
t | 41 | def split_sentence(sentance): | t | 41 | def split_sentence(sentence): |
42 | words = sentance.split() | 42 | words = sentence.split() | ||
43 | result = [] | 43 | result = [] | ||
44 | for word in words: | 44 | for word in words: | ||
45 | result.append((beginning(word), middle(word), end(word))) | 45 | result.append((beginning(word), middle(word), end(word))) | ||
46 | return result | 46 | return result | ||
47 | 47 | ||||
48 | 48 | ||||
49 | print(split_sentence("казвам се Джон Сноу")) | 49 | print(split_sentence("казвам се Джон Сноу")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordlength = len(word) | 2 | wordlength = len(word) | ||
3 | lettersIn = 0 | 3 | lettersIn = 0 | ||
4 | if wordlength % 3 == 0: | 4 | if wordlength % 3 == 0: | ||
5 | lettersIn = len(word) // 3 | 5 | lettersIn = len(word) // 3 | ||
6 | elif wordlength % 3 == 2: | 6 | elif wordlength % 3 == 2: | ||
7 | lettersIn = len(word) // 3 + 1 | 7 | lettersIn = len(word) // 3 + 1 | ||
8 | else: | 8 | else: | ||
9 | lettersIn = len(word) // 3 | 9 | lettersIn = len(word) // 3 | ||
n | 10 | return word[: int(lettersIn)] | n | 10 | return word[:lettersIn] |
11 | 11 | ||||
12 | 12 | ||||
13 | def middle(word): | 13 | def middle(word): | ||
14 | wordlength = len(word) | 14 | wordlength = len(word) | ||
15 | lettersIn = 0 | 15 | lettersIn = 0 | ||
16 | FromIndx = 0 | 16 | FromIndx = 0 | ||
17 | if wordlength % 3 == 0: | 17 | if wordlength % 3 == 0: | ||
18 | FromIndx = wordlength // 3 | 18 | FromIndx = wordlength // 3 | ||
19 | lettersIn = len(word) // 3 | 19 | lettersIn = len(word) // 3 | ||
20 | elif wordlength % 3 == 2: | 20 | elif wordlength % 3 == 2: | ||
21 | FromIndx = wordlength // 3 + 1 | 21 | FromIndx = wordlength // 3 + 1 | ||
22 | lettersIn = len(word) // 3 | 22 | lettersIn = len(word) // 3 | ||
23 | else: | 23 | else: | ||
24 | FromIndx = wordlength // 3 | 24 | FromIndx = wordlength // 3 | ||
25 | lettersIn = len(word) // 3 + 1 | 25 | lettersIn = len(word) // 3 + 1 | ||
n | 26 | return word[int(FromIndx) : int(FromIndx) + int(lettersIn)] | n | 26 | return word[FromIndx : FromIndx + lettersIn] |
27 | 27 | ||||
28 | 28 | ||||
29 | def end(word): | 29 | def end(word): | ||
30 | wordlength = len(word) | 30 | wordlength = len(word) | ||
31 | lettersIn = 0 | 31 | lettersIn = 0 | ||
32 | if wordlength % 3 == 0: | 32 | if wordlength % 3 == 0: | ||
33 | lettersIn = len(word) // 3 | 33 | lettersIn = len(word) // 3 | ||
34 | elif wordlength % 3 == 2: | 34 | elif wordlength % 3 == 2: | ||
35 | lettersIn = len(word) // 3 + 1 | 35 | lettersIn = len(word) // 3 + 1 | ||
36 | else: | 36 | else: | ||
37 | lettersIn = len(word) // 3 | 37 | lettersIn = len(word) // 3 | ||
n | 38 | return word[-int(lettersIn) :: 1] | n | 38 | return word[-lettersIn::1] |
39 | 39 | ||||
40 | 40 | ||||
41 | def split_sentence(sentance): | 41 | def split_sentence(sentance): | ||
n | 42 | words = str(sentance).split() | n | 42 | words = sentance.split() |
43 | result = [] | 43 | result = [] | ||
44 | for word in words: | 44 | for word in words: | ||
45 | result.append((beginning(word), middle(word), end(word))) | 45 | result.append((beginning(word), middle(word), end(word))) | ||
46 | return result | 46 | return result | ||
t | t | 47 | |||
48 | |||||
49 | print(split_sentence("казвам се Джон Сноу")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordlength = len(word) | 2 | wordlength = len(word) | ||
3 | lettersIn = 0 | 3 | lettersIn = 0 | ||
4 | if wordlength % 3 == 0: | 4 | if wordlength % 3 == 0: | ||
5 | lettersIn = len(word) // 3 | 5 | lettersIn = len(word) // 3 | ||
6 | elif wordlength % 3 == 2: | 6 | elif wordlength % 3 == 2: | ||
7 | lettersIn = len(word) // 3 + 1 | 7 | lettersIn = len(word) // 3 + 1 | ||
8 | else: | 8 | else: | ||
9 | lettersIn = len(word) // 3 | 9 | lettersIn = len(word) // 3 | ||
10 | return word[: int(lettersIn)] | 10 | return word[: int(lettersIn)] | ||
11 | 11 | ||||
12 | 12 | ||||
13 | def middle(word): | 13 | def middle(word): | ||
14 | wordlength = len(word) | 14 | wordlength = len(word) | ||
15 | lettersIn = 0 | 15 | lettersIn = 0 | ||
16 | FromIndx = 0 | 16 | FromIndx = 0 | ||
17 | if wordlength % 3 == 0: | 17 | if wordlength % 3 == 0: | ||
18 | FromIndx = wordlength // 3 | 18 | FromIndx = wordlength // 3 | ||
19 | lettersIn = len(word) // 3 | 19 | lettersIn = len(word) // 3 | ||
20 | elif wordlength % 3 == 2: | 20 | elif wordlength % 3 == 2: | ||
21 | FromIndx = wordlength // 3 + 1 | 21 | FromIndx = wordlength // 3 + 1 | ||
22 | lettersIn = len(word) // 3 | 22 | lettersIn = len(word) // 3 | ||
23 | else: | 23 | else: | ||
24 | FromIndx = wordlength // 3 | 24 | FromIndx = wordlength // 3 | ||
25 | lettersIn = len(word) // 3 + 1 | 25 | lettersIn = len(word) // 3 + 1 | ||
26 | return word[int(FromIndx) : int(FromIndx) + int(lettersIn)] | 26 | return word[int(FromIndx) : int(FromIndx) + int(lettersIn)] | ||
27 | 27 | ||||
28 | 28 | ||||
29 | def end(word): | 29 | def end(word): | ||
30 | wordlength = len(word) | 30 | wordlength = len(word) | ||
31 | lettersIn = 0 | 31 | lettersIn = 0 | ||
32 | if wordlength % 3 == 0: | 32 | if wordlength % 3 == 0: | ||
33 | lettersIn = len(word) // 3 | 33 | lettersIn = len(word) // 3 | ||
34 | elif wordlength % 3 == 2: | 34 | elif wordlength % 3 == 2: | ||
35 | lettersIn = len(word) // 3 + 1 | 35 | lettersIn = len(word) // 3 + 1 | ||
36 | else: | 36 | else: | ||
37 | lettersIn = len(word) // 3 | 37 | lettersIn = len(word) // 3 | ||
38 | return word[-int(lettersIn) :: 1] | 38 | return word[-int(lettersIn) :: 1] | ||
39 | 39 | ||||
40 | 40 | ||||
t | 41 | def split_sentance(sentance): | t | 41 | def split_sentence(sentance): |
42 | words = str(sentance).split() | 42 | words = str(sentance).split() | ||
43 | result = [] | 43 | result = [] | ||
44 | for word in words: | 44 | for word in words: | ||
45 | result.append((beginning(word), middle(word), end(word))) | 45 | result.append((beginning(word), middle(word), end(word))) | ||
46 | return result | 46 | return result |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|