1def beginning(word):
2 remainder = len(word) % 3
3 if remainder == 0 or remainder == 1:
4 subword_end = len(word) // 3
5 return word[0:subword_end]
6 elif remainder == 2:
7 subword_end = len(word) // 3 + 1
8 return word[0:subword_end]
9 else:
10 print("Invalid remainder after division by 3")
11
12def middle(word):
13 remainder = len(word) % 3
14 if remainder == 0:
15 subword_start = len(word) // 3
16 return word[subword_start:subword_start*2]
17 elif remainder == 2:
18 subword_start = len(word) // 3 + 1
19 subword_end = len(word) // 3 * 2 + 1
20 return word[subword_start:subword_end]
21 elif remainder == 1:
22 subword_start = len(word) // 3
23 subword_end = len(word) // 3 * 2 + 1
24 return word[subword_start:subword_end]
25 else:
26 print("Invalid remainder after division by 3")
27
28
29def end(word):
30 remainder = len(word) % 3
31 if remainder == 0:
32 subword_start = (len(word) // 3) * 2
33 return word[subword_start:]
34 elif remainder == 2 or remainder == 1:
35 subword_start = len(word) // 3 * 2 + 1
36 return word[subword_start:]
37 else:
38 print("Invalid remainder after division by 3")
39
40
41def split_sentence(sentence):
42 list_tmp = sentence.split(' ')
43 my_list = []
44 for word in list_tmp:
45 my_tuple = (beginning(word), middle(word), end(word))
46 my_list.append(my_tuple)
47 return my_list
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
17.10.2023 09:07
17.10.2023 09:07
17.10.2023 09:08