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

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

10 точки общо

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

 1def beginning(word):
 2    word_length = len(word)
 3    if word_length%3 == 0 or word_length%3 == 1:
 4         offset = word_length//3
 5         return word[0:offset]
 6    elif word_length%3 == 2:
 7        offset = word_length//3+1
 8        return word[0:offset]
 9    
10def middle(word):
11    word_length = len(word)
12    if word_length%3 == 0:
13         offset = word_length//3
14         return word[offset:offset+offset]
15    elif word_length%3 == 2:
16        offset = word_length//3
17        return word[offset+1:offset+offset+1]
18    else:
19        offset = word_length//3
20        return word[offset:offset+offset+1]
21    
22def end(word):
23    word_length = len(word)
24    if word_length%3 == 0:
25         offset = word_length//3
26         return ''.join(reversed(word[word_length:offset+offset-1:-1]))
27    elif word_length%3== 2 or word_length%3==1:
28        offset=word_length//3
29        return ''.join(reversed(word[word_length:offset+offset:-1]))
30    
31def split_sentence(sentence):
32    split_in_words = sentence.split()
33    list_of_tuples = []
34    for word in split_in_words:
35        list_of_tuples.append((beginning(word),middle(word),end(word)))
36    return list_of_tuples

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

OK

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

f1def beginning(word):f1def beginning(word):
n2    word_length=len(word)n2    word_length = len(word)
3    if word_length%3== 0:3    if word_length%3 == 0 or word_length%3 == 1:
4         offset=word_length//34         offset = word_length//3
5         return word[0:offset]5         return word[0:offset]
n6    elif word_length%3== 2:n6    elif word_length%3 == 2:
7        offset=word_length//3+17        offset = word_length//3+1
8        return word[0:offset]8        return word[0:offset]
n9    else:n9    
10        offset=word_length//3
11        return word[0:offset]
12def middle(word):10def middle(word):
n13    word_length=len(word)n11    word_length = len(word)
14    if word_length%3== 0:12    if word_length%3 == 0:
15         offset=word_length//313         offset = word_length//3
16         return word[offset:offset+offset]14         return word[offset:offset+offset]
n17    elif word_length%3== 2:n15    elif word_length%3 == 2:
18        offset=word_length//316        offset = word_length//3
19        return word[offset+1:offset+offset+1]17        return word[offset+1:offset+offset+1]
20    else:18    else:
n21        offset=word_length//3n19        offset = word_length//3
22        return word[offset:offset+offset+1]20        return word[offset:offset+offset+1]
nn21    
23def end(word):22def end(word):
n24    word_length=len(word)n23    word_length = len(word)
25    if word_length%3== 0:24    if word_length%3 == 0:
26         offset=word_length//325         offset = word_length//3
27         return ''.join(reversed(word[word_length:offset+offset-1:-1]))26         return ''.join(reversed(word[word_length:offset+offset-1:-1]))
n28    elif word_length%3== 2:n27    elif word_length%3== 2 or word_length%3==1:
29        offset=word_length//3
30        return ''.join(reversed(word[word_length:offset+offset:-1]))
31    else:
32        offset=word_length//328        offset=word_length//3
33        return ''.join(reversed(word[word_length:offset+offset:-1]))29        return ''.join(reversed(word[word_length:offset+offset:-1]))
34    30    
35def split_sentence(sentence):31def split_sentence(sentence):
t36    split_in_words=sentence.split()t32    split_in_words = sentence.split()
37    list_of_tuples=[]33    list_of_tuples = []
38    for word in split_in_words:34    for word in split_in_words:
39        list_of_tuples.append((beginning(word),middle(word),end(word)))35        list_of_tuples.append((beginning(word),middle(word),end(word)))
40    return list_of_tuples36    return list_of_tuples
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    word_length=len(word)2    word_length=len(word)
3    if word_length%3== 0:3    if word_length%3== 0:
4         offset=word_length//34         offset=word_length//3
5         return word[0:offset]5         return word[0:offset]
6    elif word_length%3== 2:6    elif word_length%3== 2:
7        offset=word_length//3+17        offset=word_length//3+1
8        return word[0:offset]8        return word[0:offset]
9    else:9    else:
10        offset=word_length//310        offset=word_length//3
11        return word[0:offset]11        return word[0:offset]
12def middle(word):12def middle(word):
13    word_length=len(word)13    word_length=len(word)
14    if word_length%3== 0:14    if word_length%3== 0:
15         offset=word_length//315         offset=word_length//3
16         return word[offset:offset+offset]16         return word[offset:offset+offset]
17    elif word_length%3== 2:17    elif word_length%3== 2:
18        offset=word_length//318        offset=word_length//3
19        return word[offset+1:offset+offset+1]19        return word[offset+1:offset+offset+1]
20    else:20    else:
21        offset=word_length//321        offset=word_length//3
22        return word[offset:offset+offset+1]22        return word[offset:offset+offset+1]
23def end(word):23def end(word):
24    word_length=len(word)24    word_length=len(word)
25    if word_length%3== 0:25    if word_length%3== 0:
26         offset=word_length//326         offset=word_length//3
27         return ''.join(reversed(word[word_length:offset+offset-1:-1]))27         return ''.join(reversed(word[word_length:offset+offset-1:-1]))
28    elif word_length%3== 2:28    elif word_length%3== 2:
29        offset=word_length//329        offset=word_length//3
30        return ''.join(reversed(word[word_length:offset+offset:-1]))30        return ''.join(reversed(word[word_length:offset+offset:-1]))
31    else:31    else:
32        offset=word_length//332        offset=word_length//3
33        return ''.join(reversed(word[word_length:offset+offset:-1]))33        return ''.join(reversed(word[word_length:offset+offset:-1]))
34    34    
35def split_sentence(sentence):35def split_sentence(sentence):
36    split_in_words=sentence.split()36    split_in_words=sentence.split()
37    list_of_tuples=[]37    list_of_tuples=[]
38    for word in split_in_words:38    for word in split_in_words:
39        list_of_tuples.append((beginning(word),middle(word),end(word)))39        list_of_tuples.append((beginning(word),middle(word),end(word)))
40    return list_of_tuples40    return list_of_tuples
t41print(split_sentence('обичам те'))t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1def beginning(word):t1def beginning(word):
2    word_length=len(word)2    word_length=len(word)
3    if word_length%3== 0:3    if word_length%3== 0:
4         offset=word_length//34         offset=word_length//3
5         return word[0:offset]5         return word[0:offset]
6    elif word_length%3== 2:6    elif word_length%3== 2:
7        offset=word_length//3+17        offset=word_length//3+1
8        return word[0:offset]8        return word[0:offset]
9    else:9    else:
10        offset=word_length//310        offset=word_length//3
11        return word[0:offset]11        return word[0:offset]
12def middle(word):12def middle(word):
13    word_length=len(word)13    word_length=len(word)
14    if word_length%3== 0:14    if word_length%3== 0:
15         offset=word_length//315         offset=word_length//3
16         return word[offset:offset+offset]16         return word[offset:offset+offset]
17    elif word_length%3== 2:17    elif word_length%3== 2:
18        offset=word_length//318        offset=word_length//3
19        return word[offset+1:offset+offset+1]19        return word[offset+1:offset+offset+1]
20    else:20    else:
21        offset=word_length//321        offset=word_length//3
22        return word[offset:offset+offset+1]22        return word[offset:offset+offset+1]
23def end(word):23def end(word):
24    word_length=len(word)24    word_length=len(word)
25    if word_length%3== 0:25    if word_length%3== 0:
26         offset=word_length//326         offset=word_length//3
27         return ''.join(reversed(word[word_length:offset+offset-1:-1]))27         return ''.join(reversed(word[word_length:offset+offset-1:-1]))
28    elif word_length%3== 2:28    elif word_length%3== 2:
29        offset=word_length//329        offset=word_length//3
30        return ''.join(reversed(word[word_length:offset+offset:-1]))30        return ''.join(reversed(word[word_length:offset+offset:-1]))
31    else:31    else:
32        offset=word_length//332        offset=word_length//3
33        return ''.join(reversed(word[word_length:offset+offset:-1]))33        return ''.join(reversed(word[word_length:offset+offset:-1]))
34    34    
35def split_sentence(sentence):35def split_sentence(sentence):
36    split_in_words=sentence.split()36    split_in_words=sentence.split()
37    list_of_tuples=[]37    list_of_tuples=[]
38    for word in split_in_words:38    for word in split_in_words:
39        list_of_tuples.append((beginning(word),middle(word),end(word)))39        list_of_tuples.append((beginning(word),middle(word),end(word)))
40    return list_of_tuples40    return list_of_tuples
41print(split_sentence('обичам те'))41print(split_sentence('обичам те'))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op