1# This is my homework.
 2
 3def beginning(string):
 4    length = len(string)
 5    reminder = length % 3
 6    times = length // 3
 7    if reminder in (0, 1):
 8        return string[:times]
 9    else:
10        return string[:times + 1]
11
12
13def middle(string):
14    length = len(string)
15    reminder = length % 3
16    times = length // 3
17    if reminder == 0:
18        return string[times:(2 * times)]
19    elif reminder == 1:
20        return string[times:(2 * times) + 1]
21    else:
22        return string[times + 1:(2 * times) + 1]
23
24
25def end(string):
26    length = len(string)
27    reminder = length % 3
28    times = length // 3
29    if reminder == 0:
30        return string[2 * times:]
31    else:
32        return string[2 * times + 1:]
33
34
35def split_sentence(sentence):
36    words = sentence.split()
37    result = []
38    for word in words:
39        result.append((beginning(word), middle(word), end(word)))
40    return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| n | 1 | # This is my homework, possibly not pip8 compatible (in future, hope to find the time) | n | 1 | # This is my homework. | 
| 2 | |||||
| 3 | 2 | ||||
| 4 | def beginning(string): | 3 | def beginning(string): | ||
| 5 | length = len(string) | 4 | length = len(string) | ||
| 6 | reminder = length % 3 | 5 | reminder = length % 3 | ||
| 7 | times = length // 3 | 6 | times = length // 3 | ||
| n | 8 | if reminder == 0: | n | 7 | if reminder in (0, 1): | 
| 9 | return string[0: times] | 8 | return string[:times] | ||
| 10 | elif reminder == 1: | ||||
| 11 | return string[0: times] | ||||
| 12 | else: | 9 | else: | ||
| n | 13 | return string[0:times + 1] | n | 10 | return string[:times + 1] | 
| 14 | 11 | ||||
| 15 | 12 | ||||
| 16 | def middle(string): | 13 | def middle(string): | ||
| 17 | length = len(string) | 14 | length = len(string) | ||
| 18 | reminder = length % 3 | 15 | reminder = length % 3 | ||
| 19 | times = length // 3 | 16 | times = length // 3 | ||
| 20 | if reminder == 0: | 17 | if reminder == 0: | ||
| n | 21 | return string[times: (2 * times)] | n | 18 | return string[times:(2 * times)] | 
| 22 | elif reminder == 1: | 19 | elif reminder == 1: | ||
| n | 23 | return string[times: (2 * times) + 1] | n | 20 | return string[times:(2 * times) + 1] | 
| 24 | else: | 21 | else: | ||
| n | 25 | return string[times+1: (2 * times) +1] | n | 22 | return string[times + 1:(2 * times) + 1] | 
| 26 | 23 | ||||
| 27 | 24 | ||||
| 28 | def end(string): | 25 | def end(string): | ||
| 29 | length = len(string) | 26 | length = len(string) | ||
| 30 | reminder = length % 3 | 27 | reminder = length % 3 | ||
| 31 | times = length // 3 | 28 | times = length // 3 | ||
| 32 | if reminder == 0: | 29 | if reminder == 0: | ||
| 33 | return string[2 * times:] | 30 | return string[2 * times:] | ||
| n | 34 | elif reminder == 1: | n | 31 | else: | 
| 35 | return string[2 * times + 1:] | 32 | return string[2 * times + 1:] | ||
| n | 36 | else: | n | ||
| 37 | return string[2*times + 1:] | ||||
| 38 | 33 | ||||
| 39 | 34 | ||||
| 40 | def split_sentence(sentence): | 35 | def split_sentence(sentence): | ||
| 41 | words = sentence.split() | 36 | words = sentence.split() | ||
| 42 | result = [] | 37 | result = [] | ||
| 43 | for word in words: | 38 | for word in words: | ||
| 44 | result.append((beginning(word), middle(word), end(word))) | 39 | result.append((beginning(word), middle(word), end(word))) | ||
| 45 | return result | 40 | return result | ||
| 46 | 41 | ||||
| t | t | 42 | 
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 
 | 
 | |||||||||
16.10.2023 21:08