Домашни > Man who speaks the ends of words > Решения > Решението на Михаела Хаджиковакева

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

10 точки общо

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

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

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

OK

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

t1def beginning(word):t1def beginning(word):
2    length = len(word)2    length = len(word)
3    count = int(length / 3)3    count = int(length / 3)
4    if length % 3 == 0:4    if length % 3 == 0:
5        return word[0:count]5        return word[0:count]
6    elif length % 3 == 1:6    elif length % 3 == 1:
7        return word[0:count]  7        return word[0:count]  
8    else:8    else:
9        return word[0:count+1]9        return word[0:count+1]
10        10        
11def middle(word):11def middle(word):
12    length = len(word)12    length = len(word)
13    count = int(length / 3)13    count = int(length / 3)
14    if length % 3 == 0:14    if length % 3 == 0:
15        return word[count:2*count]15        return word[count:2*count]
16    elif length % 3 == 1:16    elif length % 3 == 1:
17        return word[count:2*count+1]17        return word[count:2*count+1]
18    else:18    else:
19        return word[count+1:2*count+1]19        return word[count+1:2*count+1]
2020
21def end(word):21def end(word):
22    length = len(word)22    length = len(word)
23    count = int(length / 3)23    count = int(length / 3)
24    if length % 3 == 0:24    if length % 3 == 0:
25        return word[2*count:3*count]25        return word[2*count:3*count]
26    elif length % 3 == 1:26    elif length % 3 == 1:
27        return word[2*count+1:3*count+1] 27        return word[2*count+1:3*count+1] 
28    else:28    else:
29        return word[2*count+1:3*count+2]29        return word[2*count+1:3*count+2]
30        30        
31        31        
32def split_word(word):32def split_word(word):
33    return beginning(word), middle(word), end(word)33    return beginning(word), middle(word), end(word)
3434
35def split_sentence(sentence):35def split_sentence(sentence):
36    arr = sentence.split()36    arr = sentence.split()
37    result = []37    result = []
38    for word in arr:38    for word in arr:
39        result.append(split_word(word))39        result.append(split_word(word))
40    return result40    return result
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1def beginning(word):t1def beginning(word):
2    length = len(word)2    length = len(word)
3    count = int(length / 3)3    count = int(length / 3)
4    if length % 3 == 0:4    if length % 3 == 0:
5        return word[0:count]5        return word[0:count]
6    elif length % 3 == 1:6    elif length % 3 == 1:
7        return word[0:count]  7        return word[0:count]  
8    else:8    else:
9        return word[0:count+1]9        return word[0:count+1]
10        10        
11def middle(word):11def middle(word):
12    length = len(word)12    length = len(word)
13    count = int(length / 3)13    count = int(length / 3)
14    if length % 3 == 0:14    if length % 3 == 0:
15        return word[count:2*count]15        return word[count:2*count]
16    elif length % 3 == 1:16    elif length % 3 == 1:
17        return word[count:2*count+1]17        return word[count:2*count+1]
18    else:18    else:
19        return word[count+1:2*count+1]19        return word[count+1:2*count+1]
2020
21def end(word):21def end(word):
22    length = len(word)22    length = len(word)
23    count = int(length / 3)23    count = int(length / 3)
24    if length % 3 == 0:24    if length % 3 == 0:
25        return word[2*count:3*count]25        return word[2*count:3*count]
26    elif length % 3 == 1:26    elif length % 3 == 1:
27        return word[2*count+1:3*count+1] 27        return word[2*count+1:3*count+1] 
28    else:28    else:
29        return word[2*count+1:3*count+2]29        return word[2*count+1:3*count+2]
30        30        
31        31        
32def split_word(word):32def split_word(word):
33    return beginning(word), middle(word), end(word)33    return beginning(word), middle(word), end(word)
3434
35def split_sentence(sentence):35def split_sentence(sentence):
36    arr = sentence.split()36    arr = sentence.split()
37    result = []37    result = []
38    for word in arr:38    for word in arr:
39        result.append(split_word(word))39        result.append(split_word(word))
40    return result40    return result
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)
3    count = int(length / 3)3    count = int(length / 3)
4    if length % 3 == 0:4    if length % 3 == 0:
5        return word[0:count]5        return word[0:count]
6    elif length % 3 == 1:6    elif length % 3 == 1:
7        return word[0:count]  7        return word[0:count]  
8    else:8    else:
9        return word[0:count+1]9        return word[0:count+1]
10        10        
11def middle(word):11def middle(word):
12    length = len(word)12    length = len(word)
13    count = int(length / 3)13    count = int(length / 3)
14    if length % 3 == 0:14    if length % 3 == 0:
15        return word[count:2*count]15        return word[count:2*count]
16    elif length % 3 == 1:16    elif length % 3 == 1:
17        return word[count:2*count+1]17        return word[count:2*count+1]
18    else:18    else:
19        return word[count+1:2*count+1]19        return word[count+1:2*count+1]
2020
21def end(word):21def end(word):
22    length = len(word)22    length = len(word)
23    count = int(length / 3)23    count = int(length / 3)
24    if length % 3 == 0:24    if length % 3 == 0:
25        return word[2*count:3*count]25        return word[2*count:3*count]
26    elif length % 3 == 1:26    elif length % 3 == 1:
27        return word[2*count+1:3*count+1] 27        return word[2*count+1:3*count+1] 
28    else:28    else:
29        return word[2*count+1:3*count+2]29        return word[2*count+1:3*count+2]
30        30        
31        31        
32def split_word(word):32def split_word(word):
33    return beginning(word), middle(word), end(word)33    return beginning(word), middle(word), end(word)
3434
35def split_sentence(sentence):35def split_sentence(sentence):
36    arr = sentence.split()36    arr = sentence.split()
37    result = []37    result = []
38    for word in arr:38    for word in arr:
39        result.append(split_word(word))39        result.append(split_word(word))
t40    print(result)t40    return result
41 
42split_sentence('Kазвам се Джон Сноу') #-> [('Ка', 'зв', 'ам'), ('с', '', 'е'), ('Д', 'жо', 'н'), ('С', 'но', 'у')]
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op