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

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

10 точки общо

12 успешни теста
0 неуспешни теста
Код
Скрий всички коментари

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

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

OK

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

n1# This is my homework, possibly not pip8 compatible (in future, hope to find the time)n1# This is my homework.
2 
32
4def beginning(string):3def beginning(string):
5    length = len(string)4    length = len(string)
6    reminder = length % 35    reminder = length % 3
7    times = length // 36    times = length // 3
n8    if reminder == 0:n7    if reminder in (0, 1):
9        return string[0: times]8        return string[:times]
10    elif reminder == 1:
11        return string[0: times]
12    else:9    else:
n13        return string[0:times + 1]n10        return string[:times + 1]
1411
1512
16def middle(string):13def middle(string):
17    length = len(string)14    length = len(string)
18    reminder = length % 315    reminder = length % 3
19    times = length // 316    times = length // 3
20    if reminder == 0:17    if reminder == 0:
n21        return string[times: (2 * times)]n18        return string[times:(2 * times)]
22    elif reminder == 1:19    elif reminder == 1:
n23        return string[times: (2 * times) + 1]n20        return string[times:(2 * times) + 1]
24    else:21    else:
n25        return string[times+1: (2 * times) +1]n22        return string[times + 1:(2 * times) + 1]
2623
2724
28def end(string):25def end(string):
29    length = len(string)26    length = len(string)
30    reminder = length % 327    reminder = length % 3
31    times = length // 328    times = length // 3
32    if reminder == 0:29    if reminder == 0:
33        return string[2 * times:]30        return string[2 * times:]
n34    elif reminder == 1:n31    else:
35        return string[2 * times + 1:]32        return string[2 * times + 1:]
n36    else:n
37        return string[2*times + 1:]
3833
3934
40def split_sentence(sentence):35def split_sentence(sentence):
41    words = sentence.split()36    words = sentence.split()
42    result = []37    result = []
43    for word in words:38    for word in words:
44        result.append((beginning(word), middle(word), end(word)))39        result.append((beginning(word), middle(word), end(word)))
45    return result40    return result
4641
tt42 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op