1def beginning(word):
2 w_len = len(word)
3
4 if w_len % 3 == 0 or w_len % 3 == 1:
5 return word[:w_len // 3]
6 return word[:w_len // 3 + 1]
7
8
9def middle(word):
10 w_len = len(word)
11 new_len = w_len // 3
12
13 if w_len % 3 == 0:
14 return word[new_len:new_len * 2]
15 elif w_len % 3 == 1:
16 return word[new_len:new_len * 2 + 1]
17 return word[new_len + 1:new_len * 2 + 1]
18
19
20def end(word):
21 w_len = len(word)
22 new_len = w_len // 3
23
24 if w_len % 3 == 0 :
25 return word[new_len * 2:]
26 return word[new_len * 2 + 1:]
27
28
29def split_sentence(sentence):
30 words = sentence.split()
31 result = []
32
33 for word in words:
34 result.append((beginning(word), middle(word), end(word)))
35 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Георги Кунчев
12.10.2023 10:24Използвай само 4 интервала за индентация. Беза табулации. За това ще отнемаме точки.
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | w_len = len(word) | 2 | w_len = len(word) | ||
3 | 3 | ||||
n | 4 | if w_len % 3 == 0 or w_len % 3 == 1: | n | 4 | if w_len % 3 == 0 or w_len % 3 == 1: |
5 | return word[:w_len // 3] | 5 | return word[:w_len // 3] | ||
6 | return word[:w_len // 3 + 1] | 6 | return word[:w_len // 3 + 1] | ||
n | 7 | n | 7 | ||
8 | |||||
8 | def middle(word): | 9 | def middle(word): | ||
9 | w_len = len(word) | 10 | w_len = len(word) | ||
10 | new_len = w_len // 3 | 11 | new_len = w_len // 3 | ||
n | n | 12 | |||
11 | if w_len % 3 == 0: | 13 | if w_len % 3 == 0: | ||
12 | return word[new_len:new_len * 2] | 14 | return word[new_len:new_len * 2] | ||
13 | elif w_len % 3 == 1: | 15 | elif w_len % 3 == 1: | ||
14 | return word[new_len:new_len * 2 + 1] | 16 | return word[new_len:new_len * 2 + 1] | ||
15 | return word[new_len + 1:new_len * 2 + 1] | 17 | return word[new_len + 1:new_len * 2 + 1] | ||
n | 16 | n | 18 | ||
19 | |||||
17 | def end(word): | 20 | def end(word): | ||
18 | w_len = len(word) | 21 | w_len = len(word) | ||
19 | new_len = w_len // 3 | 22 | new_len = w_len // 3 | ||
n | n | 23 | |||
20 | if w_len % 3 == 0 : | 24 | if w_len % 3 == 0 : | ||
n | 21 | return word[new_len * 2:w_len] | n | 25 | return word[new_len * 2:] |
22 | return word[new_len * 2 + 1:w_len] | 26 | return word[new_len * 2 + 1:] | ||
23 | 27 | ||||
24 | 28 | ||||
25 | def split_sentence(sentence): | 29 | def split_sentence(sentence): | ||
26 | words = sentence.split() | 30 | words = sentence.split() | ||
27 | result = [] | 31 | result = [] | ||
t | t | 32 | |||
28 | for word in words: | 33 | for word in words: | ||
29 | result.append((beginning(word), middle(word), end(word))) | 34 | result.append((beginning(word), middle(word), end(word))) | ||
30 | return result | 35 | return result |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
n | 2 | w_len = len(word) | n | 2 | w_len = len(word) |
3 | 3 | ||||
4 | if w_len % 3 == 0 or w_len % 3 == 1: | 4 | if w_len % 3 == 0 or w_len % 3 == 1: | ||
5 | return word[0:w_len // 3] | 5 | return word[:w_len // 3] | ||
6 | return word[0:w_len // 3 + 1] | 6 | return word[:w_len // 3 + 1] | ||
7 | 7 | ||||
8 | def middle(word): | 8 | def middle(word): | ||
n | 9 | w_len = len(word) | n | 9 | w_len = len(word) |
10 | 10 | new_len = w_len // 3 | |||
11 | if w_len % 3 == 0: | 11 | if w_len % 3 == 0: | ||
12 | return word[w_len // 3:w_len // 3 * 2] | 12 | return word[new_len:new_len * 2] | ||
13 | elif w_len % 3 == 1: | 13 | elif w_len % 3 == 1: | ||
14 | return word[w_len // 3:w_len // 3 * 2 + 1] | 14 | return word[new_len:new_len * 2 + 1] | ||
15 | return word[w_len // 3 + 1:w_len // 3 * 2 + 1] | 15 | return word[new_len + 1:new_len * 2 + 1] | ||
16 | 16 | ||||
17 | def end(word): | 17 | def end(word): | ||
n | 18 | w_len = len(word) | n | 18 | w_len = len(word) |
19 | 19 | new_len = w_len // 3 | |||
20 | if w_len % 3 == 0 : | 20 | if w_len % 3 == 0 : | ||
21 | return word[w_len // 3 * 2:w_len] | 21 | return word[new_len * 2:w_len] | ||
22 | return word[w_len // 3 * 2 + 1:w_len] | 22 | return word[new_len * 2 + 1:w_len] | ||
23 | 23 | ||||
24 | 24 | ||||
25 | def split_sentence(sentence): | 25 | def split_sentence(sentence): | ||
t | 26 | words = sentence.split() | t | 26 | words = sentence.split() |
27 | my_list = [] | 27 | result = [] | ||
28 | for word in words: | 28 | for word in words: | ||
29 | my_list.append((beginning(word),middle(word),end(word))) | 29 | result.append((beginning(word), middle(word), end(word))) | ||
30 | return my_list | 30 | return result | ||
31 | |||||
32 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|