1PIECES = 3
2
3
4def beginning(word):
5 """Return the beginning part of a word."""
6
7 length = len(word)
8 piece = length // PIECES
9
10 if length % PIECES == 2:
11 return word[:piece + 1]
12 else:
13 return word[:piece]
14
15
16def middle(word):
17 """Return the middle part of a word."""
18
19 length = len(word)
20 piece = length // PIECES
21
22 if length % PIECES == 1:
23 return word[piece:piece * 2 + 1]
24 elif length % PIECES == 0:
25 return word[piece:piece * 2]
26 else:
27 return word[piece + 1:piece * 2 + 1]
28
29
30def end(word):
31 """Return the end part of a word."""
32
33 length = len(word)
34 piece = length // PIECES
35
36 if length % PIECES == 0:
37 return word[piece * 2:]
38 else:
39 return word[piece * 2 + 1:]
40
41
42def split_sentence(sentence):
43 """Split a sentence into a list of tuples where each tuple contains a word split to three parts."""
44
45 words = sentence.split()
46 result = []
47
48 for word in words:
49 result.append((beginning(word), middle(word), end(word)))
50
51 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Георги Кунчев
13.10.2023 14:03Добра работа. Нямам коментари.
|