Домашни > Man who speaks the ends of words > Решения > Решението на Ивайло Кънчев

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

10 точки общо

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

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

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

OK

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

t1'''dfsdf'''t
2 
3def beginning(word):1def beginning(word):
4    length = len(word)2    length = len(word)
53
6    if length % 3 == 2:4    if length % 3 == 2:
7        last_index = length // 3 + 15        last_index = length // 3 + 1
8    else:6    else:
9        last_index = length // 37        last_index = length // 3
108
11    return word[:last_index]9    return word[:last_index]
1210
13def middle(word):11def middle(word):
14    length = len(word)12    length = len(word)
15    13    
16    if length % 3 == 0:14    if length % 3 == 0:
17        first_index = length // 315        first_index = length // 3
18        last_index = 2 * length // 316        last_index = 2 * length // 3
19    elif length % 3 == 2:17    elif length % 3 == 2:
20        first_index = length // 3 + 118        first_index = length // 3 + 1
21        last_index = 2 * length // 319        last_index = 2 * length // 3
22    else:20    else:
23        first_index = length // 321        first_index = length // 3
24        last_index = 2 * length // 3 + 122        last_index = 2 * length // 3 + 1
2523
26    return word[first_index:last_index]24    return word[first_index:last_index]
2725
28def end(word):26def end(word):
29    length = len(word)27    length = len(word)
3028
31    if length % 3 == 1:29    if length % 3 == 1:
32        first_index = 2 * length // 3 + 130        first_index = 2 * length // 3 + 1
33    else:31    else:
34        first_index = 2 * length // 332        first_index = 2 * length // 3
3533
36    return word[first_index:]34    return word[first_index:]
3735
38def split_sentence(sentence):36def split_sentence(sentence):
39    words = sentence.split()37    words = sentence.split()
40    split_words = []38    split_words = []
4139
42    for word in words:40    for word in words:
43        split_words.append((beginning(word), middle(word), end(word)))41        split_words.append((beginning(word), middle(word), end(word)))
4442
45    return split_words43    return split_words
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

nn1'''dfsdf'''
2 
1def beginning(word):3def beginning(word):
2    length = len(word)4    length = len(word)
35
n4    if length % 3 == 0:n
5        last_index = length // 3
6    elif length % 3 == 2:6    if length % 3 == 2:
7        last_index = length // 3 + 17        last_index = length // 3 + 1
8    else:8    else:
9        last_index = length // 39        last_index = length // 3
1010
11    return word[:last_index]11    return word[:last_index]
1212
13def middle(word):13def middle(word):
14    length = len(word)14    length = len(word)
15    15    
16    if length % 3 == 0:16    if length % 3 == 0:
17        first_index = length // 317        first_index = length // 3
18        last_index = 2 * length // 318        last_index = 2 * length // 3
19    elif length % 3 == 2:19    elif length % 3 == 2:
20        first_index = length // 3 + 120        first_index = length // 3 + 1
21        last_index = 2 * length // 321        last_index = 2 * length // 3
22    else:22    else:
23        first_index = length // 323        first_index = length // 3
24        last_index = 2 * length // 3 + 124        last_index = 2 * length // 3 + 1
2525
26    return word[first_index:last_index]26    return word[first_index:last_index]
2727
28def end(word):28def end(word):
29    length = len(word)29    length = len(word)
3030
n31    if length % 3 == 0:n31    if length % 3 == 1:
32        first_index = 2 * length // 3 + 1
33    else:
32        first_index = 2 * length // 334        first_index = 2 * length // 3
t33    elif length % 3 == 2:t
34        first_index = 2 * length // 3
35    else:
36        first_index = 2 * length // 3 + 1
3735
38    return word[first_index:]36    return word[first_index:]
3937
40def split_sentence(sentence):38def split_sentence(sentence):
41    words = sentence.split()39    words = sentence.split()
42    split_words = []40    split_words = []
4341
44    for word in words:42    for word in words:
45        split_words.append((beginning(word), middle(word), end(word)))43        split_words.append((beginning(word), middle(word), end(word)))
4644
47    return split_words45    return split_words
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    length = len(word)2    length = len(word)
33
4    if length % 3 == 0:4    if length % 3 == 0:
5        last_index = length // 35        last_index = length // 3
6    elif length % 3 == 2:6    elif length % 3 == 2:
7        last_index = length // 3 + 17        last_index = length // 3 + 1
8    else:8    else:
9        last_index = length // 39        last_index = length // 3
1010
11    return word[:last_index]11    return word[:last_index]
1212
13def middle(word):13def middle(word):
14    length = len(word)14    length = len(word)
15    15    
16    if length % 3 == 0:16    if length % 3 == 0:
17        first_index = length // 317        first_index = length // 3
18        last_index = 2 * length // 318        last_index = 2 * length // 3
19    elif length % 3 == 2:19    elif length % 3 == 2:
20        first_index = length // 3 + 120        first_index = length // 3 + 1
21        last_index = 2 * length // 321        last_index = 2 * length // 3
22    else:22    else:
23        first_index = length // 323        first_index = length // 3
24        last_index = 2 * length // 3 + 124        last_index = 2 * length // 3 + 1
2525
26    return word[first_index:last_index]26    return word[first_index:last_index]
2727
28def end(word):28def end(word):
29    length = len(word)29    length = len(word)
3030
31    if length % 3 == 0:31    if length % 3 == 0:
32        first_index = 2 * length // 332        first_index = 2 * length // 3
33    elif length % 3 == 2:33    elif length % 3 == 2:
34        first_index = 2 * length // 334        first_index = 2 * length // 3
35    else:35    else:
36        first_index = 2 * length // 3 + 136        first_index = 2 * length // 3 + 1
3737
38    return word[first_index:]38    return word[first_index:]
3939
40def split_sentence(sentence):40def split_sentence(sentence):
41    words = sentence.split()41    words = sentence.split()
42    split_words = []42    split_words = []
4343
44    for word in words:44    for word in words:
45        split_words.append((beginning(word), middle(word), end(word)))45        split_words.append((beginning(word), middle(word), end(word)))
4646
47    return split_words47    return split_words
t48 t
49print(split_sentence('Kазвам се Джон Сноу'))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op