1def beginning(word):
2 if len(word) == 1:
3 return word
4 elif len(word) == 2:
5 return word[0]
6 elif len(word) % 3 == 0 or len(word) % 3 == 1:
7 return word[: len(word) // 3]
8 elif len(word) % 3 == 2:
9 return word[: len(word) // 3 + 1]
10
11
12def middle(word):
13 if len(word) == 1:
14 return ''
15 if len(word) == 2:
16 return ''
17 elif len(word) % 3 == 0 or len(word) % 3 == 1:
18 return word[len(word) // 3 : len(word)-len(word) // 3]
19 elif len(word) % 3 == 2:
20 return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1]
21
22def end(word):
23 if len(word) == 1:
24 return ''
25 if len(word) == 2:
26 return word[1]
27 elif len(word) % 3 == 0 or len(word) % 3 == 1:
28 return word[len(word) - len(word) // 3 :]
29 elif len(word) % 3 == 2:
30 return word[len(word) - len(word) // 3 - 1 :]
31
32def split_sentence(sentence):
33
34 a = []
35 a = sentence.split()
36 final = []
37
38 for word in a:
39 result=beginning(word) , middle(word) , end(word)
40 final.append(result)
41
42 return final
.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: [('Зд[49 chars]', 'е'), ('м', '', 'и'), ('е', '', ''), ('отв', 'ертк', 'ата')] != [('Зд[49 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 44, in test_one_letter
self.assertEqual(beginning('#'), '')
AssertionError: '#' != ''
- #
+
----------------------------------------------------------------------
Ran 12 tests in 0.001s
FAILED (failures=2)
Момчил Узунов
17.10.2023 13:57Roger that.
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | if len(word) == 1: | 2 | if len(word) == 1: | ||
3 | return word | 3 | return word | ||
4 | elif len(word) == 2: | 4 | elif len(word) == 2: | ||
5 | return word[0] | 5 | return word[0] | ||
n | 6 | elif len(word) % 3 == 0: | n | 6 | elif len(word) % 3 == 0 or len(word) % 3 == 1: |
7 | return word[: len(word) // 3] | 7 | return word[: len(word) // 3] | ||
8 | elif len(word) % 3 == 2: | 8 | elif len(word) % 3 == 2: | ||
9 | return word[: len(word) // 3 + 1] | 9 | return word[: len(word) // 3 + 1] | ||
n | 10 | elif len(word) % 3 == 1: | n | ||
11 | return word[: len(word) // 3] | ||||
12 | 10 | ||||
13 | 11 | ||||
14 | def middle(word): | 12 | def middle(word): | ||
15 | if len(word) == 1: | 13 | if len(word) == 1: | ||
n | 16 | return ' ' | n | 14 | return '' |
17 | if len(word) == 2: | 15 | if len(word) == 2: | ||
n | 18 | return ' ' | n | 16 | return '' |
19 | elif len(word) % 3 == 0: | 17 | elif len(word) % 3 == 0 or len(word) % 3 == 1: | ||
20 | |||||
21 | return word[len(word) // 3 : len(word)-len(word) // 3] | 18 | return word[len(word) // 3 : len(word)-len(word) // 3] | ||
22 | elif len(word) % 3 == 2: | 19 | elif len(word) % 3 == 2: | ||
23 | return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1] | 20 | return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1] | ||
n | 24 | elif len(word) % 3 == 1: | n | ||
25 | return word[len(word) // 3 : len(word)-len(word) // 3] | ||||
26 | 21 | ||||
27 | def end(word): | 22 | def end(word): | ||
28 | if len(word) == 1: | 23 | if len(word) == 1: | ||
n | 29 | return ' ' | n | 24 | return '' |
30 | if len(word) == 2: | 25 | if len(word) == 2: | ||
31 | return word[1] | 26 | return word[1] | ||
n | 32 | elif len(word) % 3 == 0: | n | 27 | elif len(word) % 3 == 0 or len(word) % 3 == 1: |
33 | return word[len(word) - len(word) // 3 :] | 28 | return word[len(word) - len(word) // 3 :] | ||
34 | elif len(word) % 3 == 2: | 29 | elif len(word) % 3 == 2: | ||
35 | return word[len(word) - len(word) // 3 - 1 :] | 30 | return word[len(word) - len(word) // 3 - 1 :] | ||
n | 36 | elif len(word) % 3 == 1: | n | ||
37 | return word[len(word) - len(word) // 3 :] | ||||
38 | 31 | ||||
39 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
40 | 33 | ||||
n | 41 | a=[] | n | 34 | a = [] |
42 | a=sentence.split() | 35 | a = sentence.split() | ||
43 | final=[] | 36 | final = [] | ||
44 | 37 | ||||
45 | for word in a: | 38 | for word in a: | ||
46 | result=beginning(word) , middle(word) , end(word) | 39 | result=beginning(word) , middle(word) , end(word) | ||
47 | final.append(result) | 40 | final.append(result) | ||
48 | 41 | ||||
49 | return final | 42 | return final | ||
t | 50 | t |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | if len(word) == 1: | 2 | if len(word) == 1: | ||
3 | return word | 3 | return word | ||
4 | elif len(word) == 2: | 4 | elif len(word) == 2: | ||
5 | return word[0] | 5 | return word[0] | ||
6 | elif len(word) % 3 == 0: | 6 | elif len(word) % 3 == 0: | ||
7 | return word[: len(word) // 3] | 7 | return word[: len(word) // 3] | ||
8 | elif len(word) % 3 == 2: | 8 | elif len(word) % 3 == 2: | ||
9 | return word[: len(word) // 3 + 1] | 9 | return word[: len(word) // 3 + 1] | ||
10 | elif len(word) % 3 == 1: | 10 | elif len(word) % 3 == 1: | ||
11 | return word[: len(word) // 3] | 11 | return word[: len(word) // 3] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word): | 14 | def middle(word): | ||
15 | if len(word) == 1: | 15 | if len(word) == 1: | ||
n | 16 | return '' | n | 16 | return ' ' |
17 | if len(word) == 2: | 17 | if len(word) == 2: | ||
n | 18 | return '' | n | 18 | return ' ' |
19 | elif len(word) % 3 == 0: | 19 | elif len(word) % 3 == 0: | ||
20 | 20 | ||||
21 | return word[len(word) // 3 : len(word)-len(word) // 3] | 21 | return word[len(word) // 3 : len(word)-len(word) // 3] | ||
22 | elif len(word) % 3 == 2: | 22 | elif len(word) % 3 == 2: | ||
23 | return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1] | 23 | return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1] | ||
24 | elif len(word) % 3 == 1: | 24 | elif len(word) % 3 == 1: | ||
25 | return word[len(word) // 3 : len(word)-len(word) // 3] | 25 | return word[len(word) // 3 : len(word)-len(word) // 3] | ||
26 | 26 | ||||
27 | def end(word): | 27 | def end(word): | ||
28 | if len(word) == 1: | 28 | if len(word) == 1: | ||
n | 29 | return '' | n | 29 | return ' ' |
30 | if len(word) == 2: | 30 | if len(word) == 2: | ||
31 | return word[1] | 31 | return word[1] | ||
32 | elif len(word) % 3 == 0: | 32 | elif len(word) % 3 == 0: | ||
33 | return word[len(word) - len(word) // 3 :] | 33 | return word[len(word) - len(word) // 3 :] | ||
34 | elif len(word) % 3 == 2: | 34 | elif len(word) % 3 == 2: | ||
35 | return word[len(word) - len(word) // 3 - 1 :] | 35 | return word[len(word) - len(word) // 3 - 1 :] | ||
36 | elif len(word) % 3 == 1: | 36 | elif len(word) % 3 == 1: | ||
37 | return word[len(word) - len(word) // 3 :] | 37 | return word[len(word) - len(word) // 3 :] | ||
38 | 38 | ||||
39 | def split_sentence(sentence): | 39 | def split_sentence(sentence): | ||
40 | 40 | ||||
41 | a=[] | 41 | a=[] | ||
42 | a=sentence.split() | 42 | a=sentence.split() | ||
43 | final=[] | 43 | final=[] | ||
44 | 44 | ||||
45 | for word in a: | 45 | for word in a: | ||
46 | result=beginning(word) , middle(word) , end(word) | 46 | result=beginning(word) , middle(word) , end(word) | ||
47 | final.append(result) | 47 | final.append(result) | ||
48 | 48 | ||||
t | 49 | print(final) | t | 49 | return final |
50 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | if len(word) == 1: | 2 | if len(word) == 1: | ||
3 | return word | 3 | return word | ||
4 | elif len(word) == 2: | 4 | elif len(word) == 2: | ||
5 | return word[0] | 5 | return word[0] | ||
6 | elif len(word) % 3 == 0: | 6 | elif len(word) % 3 == 0: | ||
7 | return word[: len(word) // 3] | 7 | return word[: len(word) // 3] | ||
8 | elif len(word) % 3 == 2: | 8 | elif len(word) % 3 == 2: | ||
9 | return word[: len(word) // 3 + 1] | 9 | return word[: len(word) // 3 + 1] | ||
10 | elif len(word) % 3 == 1: | 10 | elif len(word) % 3 == 1: | ||
11 | return word[: len(word) // 3] | 11 | return word[: len(word) // 3] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word): | 14 | def middle(word): | ||
15 | if len(word) == 1: | 15 | if len(word) == 1: | ||
16 | return '' | 16 | return '' | ||
17 | if len(word) == 2: | 17 | if len(word) == 2: | ||
18 | return '' | 18 | return '' | ||
19 | elif len(word) % 3 == 0: | 19 | elif len(word) % 3 == 0: | ||
20 | 20 | ||||
21 | return word[len(word) // 3 : len(word)-len(word) // 3] | 21 | return word[len(word) // 3 : len(word)-len(word) // 3] | ||
22 | elif len(word) % 3 == 2: | 22 | elif len(word) % 3 == 2: | ||
23 | return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1] | 23 | return word[len(word) // 3 + 1 : len(word)-len(word) // 3-1] | ||
24 | elif len(word) % 3 == 1: | 24 | elif len(word) % 3 == 1: | ||
25 | return word[len(word) // 3 : len(word)-len(word) // 3] | 25 | return word[len(word) // 3 : len(word)-len(word) // 3] | ||
26 | 26 | ||||
27 | def end(word): | 27 | def end(word): | ||
28 | if len(word) == 1: | 28 | if len(word) == 1: | ||
29 | return '' | 29 | return '' | ||
30 | if len(word) == 2: | 30 | if len(word) == 2: | ||
31 | return word[1] | 31 | return word[1] | ||
32 | elif len(word) % 3 == 0: | 32 | elif len(word) % 3 == 0: | ||
33 | return word[len(word) - len(word) // 3 :] | 33 | return word[len(word) - len(word) // 3 :] | ||
34 | elif len(word) % 3 == 2: | 34 | elif len(word) % 3 == 2: | ||
35 | return word[len(word) - len(word) // 3 - 1 :] | 35 | return word[len(word) - len(word) // 3 - 1 :] | ||
36 | elif len(word) % 3 == 1: | 36 | elif len(word) % 3 == 1: | ||
37 | return word[len(word) - len(word) // 3 :] | 37 | return word[len(word) - len(word) // 3 :] | ||
38 | 38 | ||||
39 | def split_sentence(sentence): | 39 | def split_sentence(sentence): | ||
40 | 40 | ||||
41 | a=[] | 41 | a=[] | ||
42 | a=sentence.split() | 42 | a=sentence.split() | ||
43 | final=[] | 43 | final=[] | ||
44 | 44 | ||||
45 | for word in a: | 45 | for word in a: | ||
46 | result=beginning(word) , middle(word) , end(word) | 46 | result=beginning(word) , middle(word) , end(word) | ||
47 | final.append(result) | 47 | final.append(result) | ||
48 | 48 | ||||
49 | print(final) | 49 | print(final) | ||
t | 50 | t | |||
51 | |||||
52 | split_sentence("Казвам се Джон Сноу") |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|