Домашни > Man who speaks the ends of words > Решения > Решението на Владимир Великов

Резултати
10 точки от тестове
0 точки от учител

10 точки общо

12 успешни теста
0 неуспешни теста
Код

 1def beginning(word):
 2    length = len(word)
 3    symbol_count = length // 3
 4
 5    match length % 3:
 6        case 0:
 7            return word[:symbol_count]
 8        case 1:
 9            return word[:symbol_count]
10        case 2:
11            return word[: symbol_count + 1]
12
13def middle(word):
14    length = len(word)
15    symbol_count = length // 3
16
17    match length % 3:
18        case 0:
19            return word[symbol_count : 2*symbol_count]
20        case 1: 
21            return word[symbol_count : 2*symbol_count + 1]
22        case 2:
23            return word[symbol_count + 1 : 2*symbol_count + 1]
24
25def end(word):
26    length = len(word)
27    symbol_count = length // 3
28
29    match length % 3:
30        case 0:
31            return word[2*symbol_count :]
32        case 1:
33            return word[2*symbol_count + 1 :]
34        case 2:
35            return word[2*symbol_count + 1 :]
36        
37def split_sentence(sentence):
38    splitted_list = []
39    splitted_str = sentence.split()
40
41    for word in splitted_str:
42        splitted_list.append((beginning(word), middle(word), end(word)))
43
44    return splitted_list

............
----------------------------------------------------------------------
Ran 12 tests in 0.000s

OK

Дискусия
История

f1def beginning(word):f1def beginning(word):
2    length = len(word)2    length = len(word)
3    symbol_count = length // 33    symbol_count = length // 3
44
5    match length % 3:5    match length % 3:
6        case 0:6        case 0:
n7            return word[0:symbol_count]n7            return word[:symbol_count]
8        case 1:8        case 1:
n9            return word[0:symbol_count]n9            return word[:symbol_count]
10        case 2:10        case 2:
n11            return word[: symbol_count + 1]n11            return word[: symbol_count + 1]
1212
13def middle(word):13def middle(word):
14    length = len(word)14    length = len(word)
15    symbol_count = length // 315    symbol_count = length // 3
1616
17    match length % 3:17    match length % 3:
18        case 0:18        case 0:
19            return word[symbol_count : 2*symbol_count]19            return word[symbol_count : 2*symbol_count]
20        case 1: 20        case 1: 
21            return word[symbol_count : 2*symbol_count + 1]21            return word[symbol_count : 2*symbol_count + 1]
22        case 2:22        case 2:
23            return word[symbol_count + 1 : 2*symbol_count + 1]23            return word[symbol_count + 1 : 2*symbol_count + 1]
2424
25def end(word):25def end(word):
26    length = len(word)26    length = len(word)
27    symbol_count = length // 327    symbol_count = length // 3
2828
29    match length % 3:29    match length % 3:
30        case 0:30        case 0:
n31            return word[2*symbol_count : length]n31            return word[2*symbol_count :]
32        case 1:32        case 1:
n33            return word[2*symbol_count + 1 : length]n33            return word[2*symbol_count + 1 :]
34        case 2:34        case 2:
n35            return word[2*symbol_count + 1 : length]n35            return word[2*symbol_count + 1 :]
36        36        
37def split_sentence(sentence):37def split_sentence(sentence):
38    splitted_list = []38    splitted_list = []
t39    splitted_str = str.split(sentence, ' ')t39    splitted_str = sentence.split()
4040
41    for word in splitted_str:41    for word in splitted_str:
42        splitted_list.append((beginning(word), middle(word), end(word)))42        splitted_list.append((beginning(word), middle(word), end(word)))
4343
44    return splitted_list44    return splitted_list
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op