1def beginning(word):
2 length = len(word)
3 step = length // 3
4 if length % 3 in (0, 1):
5 return word[:step]
6 elif length % 3 == 2:
7 return word[:(step + 1)]
8
9def middle(word):
10 length = len(word)
11 step = length // 3
12 if length % 3 == 0:
13 return word[step:(step * 2)]
14 elif length % 3 == 1:
15 return word[step:(step * 2 + 1)]
16 elif length % 3 == 2:
17 return word[(step + 1):(step * 2 + 1)]
18
19def end(word):
20 length = len(word)
21 step = length // 3
22 if length % 3 == 0:
23 return word[(step * 2):]
24 elif length % 3 in (1, 2):
25 return word[(step * 2 + 1):]
26
27def split_sentence(sentence):
28 words = sentence.split()
29 counter = 0;
30 for i in words:
31 first = beginning(i)
32 mid = middle(i)
33 last = end(i)
34 words[counter] = (first, mid, last)
35 counter += 1
36 return words
............
----------------------------------------------------------------------
Ran 12 tests in 0.001s
OK
Георги Кунчев
17.10.2023 00:12Никога не сме казвали, че имаш само един опит за качване. Няма ограничения, така че - да, качи си без табулации, за да нямаш махнати точки. Относно интервалите и табовете:
https://stackoverflow.com/questions/36814642/visual-studio-code-convert-spaces-to-tabs
|
Стелиан Витанов
16.10.2023 22:05Аз си пиша програмите във Visual Studio Code и то автоматично ми се създава индентация, когато влизам във цикъл, функция,...
Въпросът ми е дали трябва да изтривам тази индентация ръчно и да я правя пак с 4 интервала, или има някакъв автоматизиран начин.
И друго, има ли смисъл сега да си редактирам кода и пак да го кача, или имам право само на един опит?
Благодаря за рецензията!
|
Георги Кунчев
16.10.2023 21:17Индентирай кода с 4 интервала. За наличие на табулации ще махаме точки.
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
3 | step = length // 3 | 3 | step = length // 3 | ||
n | 4 | if length % 3 == 0 or length % 3 == 1: | n | 4 | if length % 3 in (0, 1): |
5 | return word[:step] | 5 | return word[:step] | ||
6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
7 | return word[:(step + 1)] | 7 | return word[:(step + 1)] | ||
8 | 8 | ||||
9 | def middle(word): | 9 | def middle(word): | ||
10 | length = len(word) | 10 | length = len(word) | ||
11 | step = length // 3 | 11 | step = length // 3 | ||
12 | if length % 3 == 0: | 12 | if length % 3 == 0: | ||
13 | return word[step:(step * 2)] | 13 | return word[step:(step * 2)] | ||
14 | elif length % 3 == 1: | 14 | elif length % 3 == 1: | ||
15 | return word[step:(step * 2 + 1)] | 15 | return word[step:(step * 2 + 1)] | ||
16 | elif length % 3 == 2: | 16 | elif length % 3 == 2: | ||
17 | return word[(step + 1):(step * 2 + 1)] | 17 | return word[(step + 1):(step * 2 + 1)] | ||
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
21 | step = length // 3 | 21 | step = length // 3 | ||
22 | if length % 3 == 0: | 22 | if length % 3 == 0: | ||
23 | return word[(step * 2):] | 23 | return word[(step * 2):] | ||
t | 24 | elif length % 3 == 1 or length % 3 == 2: | t | 24 | elif length % 3 in (1, 2): |
25 | return word[(step * 2 + 1):] | 25 | return word[(step * 2 + 1):] | ||
26 | 26 | ||||
27 | def split_sentence(sentence): | 27 | def split_sentence(sentence): | ||
28 | words = sentence.split() | 28 | words = sentence.split() | ||
29 | counter = 0; | 29 | counter = 0; | ||
30 | for i in words: | 30 | for i in words: | ||
31 | first = beginning(i) | 31 | first = beginning(i) | ||
32 | mid = middle(i) | 32 | mid = middle(i) | ||
33 | last = end(i) | 33 | last = end(i) | ||
34 | words[counter] = (first, mid, last) | 34 | words[counter] = (first, mid, last) | ||
35 | counter += 1 | 35 | counter += 1 | ||
36 | return words | 36 | return words |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
3 | step = length // 3 | 3 | step = length // 3 | ||
4 | if length % 3 == 0 or length % 3 == 1: | 4 | if length % 3 == 0 or length % 3 == 1: | ||
5 | return word[:step] | 5 | return word[:step] | ||
6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
7 | return word[:(step + 1)] | 7 | return word[:(step + 1)] | ||
8 | 8 | ||||
9 | def middle(word): | 9 | def middle(word): | ||
10 | length = len(word) | 10 | length = len(word) | ||
11 | step = length // 3 | 11 | step = length // 3 | ||
12 | if length % 3 == 0: | 12 | if length % 3 == 0: | ||
13 | return word[step:(step * 2)] | 13 | return word[step:(step * 2)] | ||
14 | elif length % 3 == 1: | 14 | elif length % 3 == 1: | ||
t | 15 | return word[step:(step * 2 + 1)] | t | 15 | return word[step:(step * 2 + 1)] |
16 | elif length % 3 == 2: | 16 | elif length % 3 == 2: | ||
17 | return word[(step + 1):(step * 2 + 1)] | 17 | return word[(step + 1):(step * 2 + 1)] | ||
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
21 | step = length // 3 | 21 | step = length // 3 | ||
22 | if length % 3 == 0: | 22 | if length % 3 == 0: | ||
23 | return word[(step * 2):] | 23 | return word[(step * 2):] | ||
24 | elif length % 3 == 1 or length % 3 == 2: | 24 | elif length % 3 == 1 or length % 3 == 2: | ||
25 | return word[(step * 2 + 1):] | 25 | return word[(step * 2 + 1):] | ||
26 | 26 | ||||
27 | def split_sentence(sentence): | 27 | def split_sentence(sentence): | ||
28 | words = sentence.split() | 28 | words = sentence.split() | ||
29 | counter = 0; | 29 | counter = 0; | ||
30 | for i in words: | 30 | for i in words: | ||
31 | first = beginning(i) | 31 | first = beginning(i) | ||
32 | mid = middle(i) | 32 | mid = middle(i) | ||
33 | last = end(i) | 33 | last = end(i) | ||
34 | words[counter] = (first, mid, last) | 34 | words[counter] = (first, mid, last) | ||
35 | counter += 1 | 35 | counter += 1 | ||
36 | return words | 36 | return words |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
n | 2 | n = len(word) | n | 2 | length = len(word) |
3 | step = n // 3 | 3 | step = length // 3 | ||
4 | if n % 3 == 0: | 4 | if length % 3 == 0 or length % 3 == 1: | ||
5 | return word[0:step] | 5 | return word[:step] | ||
6 | elif n % 3 == 1: | 6 | elif length % 3 == 2: | ||
7 | return word[0:step] | 7 | return word[:(step + 1)] | ||
8 | elif n % 3 == 2: | ||||
9 | return word[0:(step + 1)] | ||||
10 | 8 | ||||
11 | def middle(word): | 9 | def middle(word): | ||
n | 12 | n = len(word) | n | 10 | length = len(word) |
13 | step = n // 3 | 11 | step = length // 3 | ||
14 | if n % 3 == 0: | 12 | if length % 3 == 0: | ||
15 | return word[step:(step * 2)] | 13 | return word[step:(step * 2)] | ||
16 | elif n % 3 == 1: | 14 | elif length % 3 == 1: | ||
17 | return word[step:(step * 2 + 1)] | 15 | return word[step:(step * 2 + 1)] | ||
18 | elif n % 3 == 2: | 16 | elif length % 3 == 2: | ||
19 | return word[(step + 1):(step * 2 + 1)] | 17 | return word[(step + 1):(step * 2 + 1)] | ||
20 | 18 | ||||
21 | def end(word): | 19 | def end(word): | ||
n | 22 | n = len(word) | n | 20 | length = len(word) |
23 | step = n // 3 | 21 | step = length // 3 | ||
24 | if n % 3 == 0: | 22 | if length % 3 == 0: | ||
25 | return word[(step * 2):] | 23 | return word[(step * 2):] | ||
26 | elif n % 3 == 1: | 24 | elif length % 3 == 1 or length % 3 == 2: | ||
27 | return word[(step * 2 + 1):] | 25 | return word[(step * 2 + 1):] | ||
28 | elif n % 3 == 2: | ||||
29 | return word[(step * 2 + 1):] | ||||
30 | 26 | ||||
31 | def split_sentence(sentence): | 27 | def split_sentence(sentence): | ||
t | 32 | words = sentence.split() | t | 28 | words = sentence.split() |
33 | counter = 0; | 29 | counter = 0; | ||
34 | for i in words: | 30 | for i in words: | ||
35 | first = beginning(i) | 31 | first = beginning(i) | ||
36 | mid = middle(i) | 32 | mid = middle(i) | ||
37 | last = end(i) | 33 | last = end(i) | ||
38 | temp = (first, mid, last) | 34 | words[counter] = (first, mid, last) | ||
39 | words[counter] = temp | 35 | counter += 1 | ||
40 | counter += 1 | 36 | return words | ||
41 | return words | ||||
42 | |||||
43 | '''a = "непротивоконституционствувателствувайте" | ||||
44 | sentence = 'Аз съм Брад Пит и играя в Троя' | ||||
45 | print(beginning(a)) | ||||
46 | print(middle(a)) | ||||
47 | print(end(a)) | ||||
48 | print(split_sentence(sentence))''' |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|