1def beginning(word):
2 length = len(word)
3 if len(word) % 3 == 2:
4 return word[:length//3+1]
5 return word[:length//3]
6
7def middle(word):
8 length = len(word)
9 if length % 3 == 0:
10 return word[length//3:length//3*2]
11 elif length % 3 == 2:
12 return word[length//3+1:length//3*2+1]
13 return word[length//3:2*length//3+1]
14
15def end(word):
16 length = len(word)
17 if length % 3 == 0:
18 return word[2*length//3:]
19 return word[length//3*2+1:]
20
21def split_sentence(sentence):
22 result = []
23 for word in sentence.split():
24 result.append((beginning(word), middle(word), end(word)))
25 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Георги Кунчев
12.10.2023 10:45Да, сега вече всичко с табулациите е наред. Нямам други коментари по кода, които се заслужава да бъдат споделени.
|
Пламена Николова
12.10.2023 10:39Добавих това в json файла на VS Code. Надявам се вече да излиза и при вас с 4 интервала. При мен не дава грешка.
"[python]": {
"editor.detectIndentation" : false,
"editor.insertSpaces": true,
"editor.tabSize": 4
}
Поправих всичко друго. Благодаря за бързия отзив.
|
Георги Кунчев
12.10.2023 09:39Използвай 4 интервала, а не табулация. За такава дреболия ще махаме точки.
|
n | 1 | def beginning(word): | n | 1 | def beginning(word): |
2 | length = len(word) | ||||
2 | if len(word) % 3 == 2: | 3 | if len(word) % 3 == 2: | ||
n | 3 | return word[:len(word)//3+1] | n | 4 | return word[:length//3+1] |
4 | return word[:len(word)//3] | 5 | return word[:length//3] | ||
5 | 6 | ||||
6 | def middle(word): | 7 | def middle(word): | ||
n | 7 | if len(word) % 3 == 0: | n | 8 | length = len(word) |
8 | return word[len(word)//3:len(word)//3*2] | 9 | if length % 3 == 0: | ||
9 | elif len(word) % 3 == 2: | 10 | return word[length//3:length//3*2] | ||
10 | return word[len(word)//3+1:len(word)//3*2+1] | 11 | elif length % 3 == 2: | ||
11 | return word[len(word)//3:2*len(word)//3+1] | 12 | return word[length//3+1:length//3*2+1] | ||
13 | return word[length//3:2*length//3+1] | ||||
12 | 14 | ||||
13 | def end(word): | 15 | def end(word): | ||
n | n | 16 | length = len(word) | ||
14 | if len(word) % 3 == 0: | 17 | if length % 3 == 0: | ||
15 | return word[2*len(word)//3:] | 18 | return word[2*length//3:] | ||
16 | return word[len(word)//3*2+1:] | 19 | return word[length//3*2+1:] | ||
17 | 20 | ||||
18 | def split_sentence(sentence): | 21 | def split_sentence(sentence): | ||
t | 19 | result = [] | t | 22 | result = [] |
20 | words = sentence.split() | 23 | for word in sentence.split(): | ||
21 | for word in words: | ||||
22 | result.append((beginning(word), middle(word), end(word))) | 24 | result.append((beginning(word), middle(word), end(word))) | ||
23 | return result | 25 | return result | ||
24 | print(split_sentence("Kазвам се Джон Сноу")) | 26 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | if len(word) % 3 == 2: | 2 | if len(word) % 3 == 2: | ||
3 | return word[:len(word)//3+1] | 3 | return word[:len(word)//3+1] | ||
4 | return word[:len(word)//3] | 4 | return word[:len(word)//3] | ||
5 | 5 | ||||
6 | def middle(word): | 6 | def middle(word): | ||
7 | if len(word) % 3 == 0: | 7 | if len(word) % 3 == 0: | ||
8 | return word[len(word)//3:len(word)//3*2] | 8 | return word[len(word)//3:len(word)//3*2] | ||
9 | elif len(word) % 3 == 2: | 9 | elif len(word) % 3 == 2: | ||
10 | return word[len(word)//3+1:len(word)//3*2+1] | 10 | return word[len(word)//3+1:len(word)//3*2+1] | ||
11 | return word[len(word)//3:2*len(word)//3+1] | 11 | return word[len(word)//3:2*len(word)//3+1] | ||
12 | 12 | ||||
13 | def end(word): | 13 | def end(word): | ||
14 | if len(word) % 3 == 0: | 14 | if len(word) % 3 == 0: | ||
15 | return word[2*len(word)//3:] | 15 | return word[2*len(word)//3:] | ||
16 | return word[len(word)//3*2+1:] | 16 | return word[len(word)//3*2+1:] | ||
17 | 17 | ||||
t | t | 18 | def split_sentence(sentence): | ||
19 | result = [] | ||||
20 | words = sentence.split() | ||||
21 | for word in words: | ||||
22 | result.append((beginning(word), middle(word), end(word))) | ||||
23 | return result | ||||
24 | print(split_sentence("Kазвам се Джон Сноу")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|