1def beginning(word):
2 section = len(word) // 3
3
4 match len(word) % 3:
5 case 0 | 1:
6 return word[0:section]
7 case 2:
8 return word[0:(section + 1)]
9
10def middle(word):
11 section = len(word) // 3
12
13 match len(word) % 3:
14 case 0:
15 return word[section:(2 * section)]
16 case 1:
17 return word[section:(2 * section + 1)]
18 case 2:
19 return word[(section + 1):(2 * section + 1)]
20
21def end(word):
22 section = len(word) // 3
23
24 match len(word) % 3:
25 case 0:
26 return word[(2 * section):(len(word))]
27 case 1 | 2:
28 return word[(2 * section + 1):(len(word))]
29
30def split_sentence(sentence):
31 sentence_by_words = []
32
33 for word in sentence.split(" "):
34 sentence_by_words.append((beginning(word), middle(word), end(word)))
35
36 return sentence_by_words
37
38print(beginning("шах"))
39print(beginning("Враца"))
40print(beginning("барабани"))
41print("_________")
42print(middle("123456"))
43print(middle("1234567"))
44print(middle("12345678"))
45print("_________")
46print(end("123456"))
47print(end("1234567"))
48print(end("12345678"))
49print("_________")
50print(split_sentence("Kазвам се Джон Сноу"))
51print(split_sentence("Де всяко домашно да беше такова"))
52print(split_sentence("Искам сникърс"))
53print(split_sentence("Is this code PEP8 friendly?"))
ш
Вр
бар
_________
34
345
45
_________
56
67
678
_________
[('Kа', 'зв', 'ам'), ('с', '', 'е'), ('Д', 'жо', 'н'), ('С', 'но', 'у')]
[('Д', '', 'е'), ('вс', 'я', 'ко'), ('до', 'маш', 'но'), ('д', '', 'а'), ('б', 'еш', 'е'), ('та', 'ко', 'ва')]
[('Ис', 'к', 'ам'), ('сн', 'икъ', 'рс')]
[('I', '', 's'), ('t', 'hi', 's'), ('c', 'od', 'e'), ('P', 'EP', '8'), ('fri', 'end', 'ly?')]
............
----------------------------------------------------------------------
Ran 12 tests in 0.001s
OK
Георги Кунчев
12.10.2023 11:50Малък или не, нека го има черно на бяло.
Правата на студентите за изтриване на каквото и да било от сайта са сведени до минимум, за да имаме ясна история за всичко, което се е случило (без да ровим логове), и да сведем възможността за скриване на нещо важно до минимум.
ПП: Не го мисли сайта :) Ако тези няколко килобайта го гътнат, значи сме абсолютни аматьори.
|
Пламена Стоянова
12.10.2023 11:48Защо не можем да си изтриваме качените решения? Хубаво е да имаме история на какво сме поправяли, но за такива small fixes не натовармаве ли допълнително сайта?
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | section = len(word) // 3 | 2 | section = len(word) // 3 | ||
3 | 3 | ||||
4 | match len(word) % 3: | 4 | match len(word) % 3: | ||
5 | case 0 | 1: | 5 | case 0 | 1: | ||
6 | return word[0:section] | 6 | return word[0:section] | ||
7 | case 2: | 7 | case 2: | ||
8 | return word[0:(section + 1)] | 8 | return word[0:(section + 1)] | ||
9 | 9 | ||||
10 | def middle(word): | 10 | def middle(word): | ||
11 | section = len(word) // 3 | 11 | section = len(word) // 3 | ||
12 | 12 | ||||
13 | match len(word) % 3: | 13 | match len(word) % 3: | ||
14 | case 0: | 14 | case 0: | ||
15 | return word[section:(2 * section)] | 15 | return word[section:(2 * section)] | ||
16 | case 1: | 16 | case 1: | ||
17 | return word[section:(2 * section + 1)] | 17 | return word[section:(2 * section + 1)] | ||
18 | case 2: | 18 | case 2: | ||
19 | return word[(section + 1):(2 * section + 1)] | 19 | return word[(section + 1):(2 * section + 1)] | ||
20 | 20 | ||||
21 | def end(word): | 21 | def end(word): | ||
22 | section = len(word) // 3 | 22 | section = len(word) // 3 | ||
23 | 23 | ||||
24 | match len(word) % 3: | 24 | match len(word) % 3: | ||
25 | case 0: | 25 | case 0: | ||
26 | return word[(2 * section):(len(word))] | 26 | return word[(2 * section):(len(word))] | ||
n | 27 | case 1: | n | 27 | case 1 | 2: |
28 | return word[(2 * section + 1):(len(word))] | ||||
29 | case 2: | ||||
30 | return word[(2 * section + 1):(len(word))] | 28 | return word[(2 * section + 1):(len(word))] | ||
31 | 29 | ||||
32 | def split_sentence(sentence): | 30 | def split_sentence(sentence): | ||
33 | sentence_by_words = [] | 31 | sentence_by_words = [] | ||
34 | 32 | ||||
35 | for word in sentence.split(" "): | 33 | for word in sentence.split(" "): | ||
36 | sentence_by_words.append((beginning(word), middle(word), end(word))) | 34 | sentence_by_words.append((beginning(word), middle(word), end(word))) | ||
37 | 35 | ||||
38 | return sentence_by_words | 36 | return sentence_by_words | ||
39 | 37 | ||||
40 | print(beginning("шах")) | 38 | print(beginning("шах")) | ||
41 | print(beginning("Враца")) | 39 | print(beginning("Враца")) | ||
42 | print(beginning("барабани")) | 40 | print(beginning("барабани")) | ||
43 | print("_________") | 41 | print("_________") | ||
44 | print(middle("123456")) | 42 | print(middle("123456")) | ||
45 | print(middle("1234567")) | 43 | print(middle("1234567")) | ||
46 | print(middle("12345678")) | 44 | print(middle("12345678")) | ||
47 | print("_________") | 45 | print("_________") | ||
48 | print(end("123456")) | 46 | print(end("123456")) | ||
49 | print(end("1234567")) | 47 | print(end("1234567")) | ||
50 | print(end("12345678")) | 48 | print(end("12345678")) | ||
51 | print("_________") | 49 | print("_________") | ||
52 | print(split_sentence("Kазвам се Джон Сноу")) | 50 | print(split_sentence("Kазвам се Джон Сноу")) | ||
53 | print(split_sentence("Де всяко домашно да беше такова")) | 51 | print(split_sentence("Де всяко домашно да беше такова")) | ||
54 | print(split_sentence("Искам сникърс")) | 52 | print(split_sentence("Искам сникърс")) | ||
t | t | 53 | print(split_sentence("Is this code PEP8 friendly?")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | def beginning(word): | t | 1 | def beginning(word): |
2 | section = len(word) // 3 | 2 | section = len(word) // 3 | ||
3 | 3 | ||||
4 | match len(word) % 3: | 4 | match len(word) % 3: | ||
5 | case 0 | 1: | 5 | case 0 | 1: | ||
6 | return word[0:section] | 6 | return word[0:section] | ||
7 | case 2: | 7 | case 2: | ||
8 | return word[0:(section + 1)] | 8 | return word[0:(section + 1)] | ||
9 | 9 | ||||
10 | def middle(word): | 10 | def middle(word): | ||
11 | section = len(word) // 3 | 11 | section = len(word) // 3 | ||
12 | 12 | ||||
13 | match len(word) % 3: | 13 | match len(word) % 3: | ||
14 | case 0: | 14 | case 0: | ||
15 | return word[section:(2 * section)] | 15 | return word[section:(2 * section)] | ||
16 | case 1: | 16 | case 1: | ||
17 | return word[section:(2 * section + 1)] | 17 | return word[section:(2 * section + 1)] | ||
18 | case 2: | 18 | case 2: | ||
19 | return word[(section + 1):(2 * section + 1)] | 19 | return word[(section + 1):(2 * section + 1)] | ||
20 | 20 | ||||
21 | def end(word): | 21 | def end(word): | ||
22 | section = len(word) // 3 | 22 | section = len(word) // 3 | ||
23 | 23 | ||||
24 | match len(word) % 3: | 24 | match len(word) % 3: | ||
25 | case 0: | 25 | case 0: | ||
26 | return word[(2 * section):(len(word))] | 26 | return word[(2 * section):(len(word))] | ||
27 | case 1: | 27 | case 1: | ||
28 | return word[(2 * section + 1):(len(word))] | 28 | return word[(2 * section + 1):(len(word))] | ||
29 | case 2: | 29 | case 2: | ||
30 | return word[(2 * section + 1):(len(word))] | 30 | return word[(2 * section + 1):(len(word))] | ||
31 | 31 | ||||
32 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
33 | sentence_by_words = [] | 33 | sentence_by_words = [] | ||
34 | 34 | ||||
35 | for word in sentence.split(" "): | 35 | for word in sentence.split(" "): | ||
36 | sentence_by_words.append((beginning(word), middle(word), end(word))) | 36 | sentence_by_words.append((beginning(word), middle(word), end(word))) | ||
37 | 37 | ||||
38 | return sentence_by_words | 38 | return sentence_by_words | ||
39 | 39 | ||||
40 | print(beginning("шах")) | 40 | print(beginning("шах")) | ||
41 | print(beginning("Враца")) | 41 | print(beginning("Враца")) | ||
42 | print(beginning("барабани")) | 42 | print(beginning("барабани")) | ||
43 | print("_________") | 43 | print("_________") | ||
44 | print(middle("123456")) | 44 | print(middle("123456")) | ||
45 | print(middle("1234567")) | 45 | print(middle("1234567")) | ||
46 | print(middle("12345678")) | 46 | print(middle("12345678")) | ||
47 | print("_________") | 47 | print("_________") | ||
48 | print(end("123456")) | 48 | print(end("123456")) | ||
49 | print(end("1234567")) | 49 | print(end("1234567")) | ||
50 | print(end("12345678")) | 50 | print(end("12345678")) | ||
51 | print("_________") | 51 | print("_________") | ||
52 | print(split_sentence("Kазвам се Джон Сноу")) | 52 | print(split_sentence("Kазвам се Джон Сноу")) | ||
53 | print(split_sentence("Де всяко домашно да беше такова")) | 53 | print(split_sentence("Де всяко домашно да беше такова")) | ||
54 | print(split_sentence("Искам сникърс")) | 54 | print(split_sentence("Искам сникърс")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
12.10.2023 11:53
12.10.2023 11:54