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

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

10 точки общо

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

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

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

OK

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

f1def beginning(word):f1def beginning(word):
2    length = len(word)2    length = len(word)
3    if length % 3 == 0:3    if length % 3 == 0:
4        return word[:length // 3]4        return word[:length // 3]
5    elif length % 3 == 1:5    elif length % 3 == 1:
6        return word[:length // 3]6        return word[:length // 3]
7    else:7    else:
8        return word[:length // 3 + 1]8        return word[:length // 3 + 1]
99
10def middle(word):10def middle(word):
11    length = len(word)11    length = len(word)
12    if length % 3 == 0:12    if length % 3 == 0:
n13        return word[length // 3:2 * length // 3]n13        return word[length // 3 : 2 * length // 3]
14    elif length % 3 == 1:14    elif length % 3 == 1:
n15        return word[length // 3: 2*length // 3 +1]n15        return word[length // 3 : 2 * length // 3 + 1]
16    else:16    else:
n17        return word[length // 3 + 1:2 * length // 3]n17        return word[length // 3 + 1 : 2 * length // 3]
1818
19def end(word):19def end(word):
20    length = len(word)20    length = len(word)
21    if length % 3 == 0:21    if length % 3 == 0:
22        return word[2 * length // 3:]22        return word[2 * length // 3:]
23    elif length % 3 == 1:23    elif length % 3 == 1:
n24        return word[2 * length// 3+1:]n24        return word[2 * length// 3 + 1:]
25    else:25    else:
26        return word[2 * length // 3:]26        return word[2 * length // 3:]
2727
28def split_sentence(sentence):28def split_sentence(sentence):
29    words = sentence.split()29    words = sentence.split()
30    result = []30    result = []
31    for word in words:31    for word in words:
32        result.append((beginning(word), middle(word), end(word)))32        result.append((beginning(word), middle(word), end(word)))
33    return result33    return result
tt34 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op