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

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

10 точки общо

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

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.001s

OK

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

f1def beginning(word):f1def beginning(word):
2    length = len(word)2    length = len(word)
3    upper_bound = length // 33    upper_bound = length // 3
4    if length % 3 in (0,1):4    if length % 3 in (0,1):
5        return word[:upper_bound]5        return word[:upper_bound]
6    elif length % 3 == 2:6    elif length % 3 == 2:
7        return word[:(upper_bound + 1)]7        return word[:(upper_bound + 1)]
88
9def middle(word):9def middle(word):
10    length = len(word)10    length = len(word)
11    upper_bound = length // 311    upper_bound = length // 3
12    if length % 3 == 0:12    if length % 3 == 0:
13        return word[upper_bound:(upper_bound*2)]13        return word[upper_bound:(upper_bound*2)]
14    elif length % 3 == 2:14    elif length % 3 == 2:
15        return word[upper_bound+1:(2*upper_bound + 1)]15        return word[upper_bound+1:(2*upper_bound + 1)]
16    elif length % 3 == 1:16    elif length % 3 == 1:
17        return word[upper_bound:(2*upper_bound + 1)]17        return word[upper_bound:(2*upper_bound + 1)]
18    18    
19def end(word):19def end(word):
20    length = len(word)20    length = len(word)
21    upper_bound = length // 321    upper_bound = length // 3
22    if length % 3 == 0:22    if length % 3 == 0:
23        return word[(upper_bound*2):]23        return word[(upper_bound*2):]
24    elif length % 3 == 2:24    elif length % 3 == 2:
25        return word[(2*upper_bound + 1):]25        return word[(2*upper_bound + 1):]
26    elif length % 3 == 1:26    elif length % 3 == 1:
27        return word[(2 * upper_bound + 1):]27        return word[(2 * upper_bound + 1):]
28    28    
29def split_word(word):29def split_word(word):
30    return beginning(word), middle(word), end(word)30    return beginning(word), middle(word), end(word)
3131
32def split_sentence(sentence):32def split_sentence(sentence):
33    my_list = []33    my_list = []
34    list_from_sentence = sentence.split()34    list_from_sentence = sentence.split()
35    for word in list_from_sentence:35    for word in list_from_sentence:
36        my_list.append(split_word(word))36        my_list.append(split_word(word))
37    return my_list37    return my_list
t38 t
39print(split_sentence('Kазвам се Джон Сноу'))
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    upper_bound = length // 33    upper_bound = length // 3
n4    if length % 3 == 0 or length % 3 == 1:n4    if length % 3 in (0,1):
5        return word[:upper_bound]5        return word[:upper_bound]
6    elif length % 3 == 2:6    elif length % 3 == 2:
7        return word[:(upper_bound + 1)]7        return word[:(upper_bound + 1)]
88
9def middle(word):9def middle(word):
10    length = len(word)10    length = len(word)
11    upper_bound = length // 311    upper_bound = length // 3
12    if length % 3 == 0:12    if length % 3 == 0:
13        return word[upper_bound:(upper_bound*2)]13        return word[upper_bound:(upper_bound*2)]
14    elif length % 3 == 2:14    elif length % 3 == 2:
15        return word[upper_bound+1:(2*upper_bound + 1)]15        return word[upper_bound+1:(2*upper_bound + 1)]
16    elif length % 3 == 1:16    elif length % 3 == 1:
17        return word[upper_bound:(2*upper_bound + 1)]17        return word[upper_bound:(2*upper_bound + 1)]
18    18    
19def end(word):19def end(word):
20    length = len(word)20    length = len(word)
21    upper_bound = length // 321    upper_bound = length // 3
22    if length % 3 == 0:22    if length % 3 == 0:
23        return word[(upper_bound*2):]23        return word[(upper_bound*2):]
24    elif length % 3 == 2:24    elif length % 3 == 2:
25        return word[(2*upper_bound + 1):]25        return word[(2*upper_bound + 1):]
26    elif length % 3 == 1:26    elif length % 3 == 1:
27        return word[(2 * upper_bound + 1):]27        return word[(2 * upper_bound + 1):]
28    28    
29def split_word(word):29def split_word(word):
30    return beginning(word), middle(word), end(word)30    return beginning(word), middle(word), end(word)
3131
32def split_sentence(sentence):32def split_sentence(sentence):
33    my_list = []33    my_list = []
34    list_from_sentence = sentence.split()34    list_from_sentence = sentence.split()
35    for word in list_from_sentence:35    for word in list_from_sentence:
36        my_list.append(split_word(word))36        my_list.append(split_word(word))
37    return my_list37    return my_list
tt38 
39print(split_sentence('Kазвам се Джон Сноу'))
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    upper_bound = length // 33    upper_bound = length // 3
4    if length % 3 == 0 or length % 3 == 1:4    if length % 3 == 0 or length % 3 == 1:
5        return word[:upper_bound]5        return word[:upper_bound]
6    elif length % 3 == 2:6    elif length % 3 == 2:
7        return word[:(upper_bound + 1)]7        return word[:(upper_bound + 1)]
88
9def middle(word):9def middle(word):
10    length = len(word)10    length = len(word)
11    upper_bound = length // 311    upper_bound = length // 3
12    if length % 3 == 0:12    if length % 3 == 0:
13        return word[upper_bound:(upper_bound*2)]13        return word[upper_bound:(upper_bound*2)]
14    elif length % 3 == 2:14    elif length % 3 == 2:
15        return word[upper_bound+1:(2*upper_bound + 1)]15        return word[upper_bound+1:(2*upper_bound + 1)]
16    elif length % 3 == 1:16    elif length % 3 == 1:
17        return word[upper_bound:(2*upper_bound + 1)]17        return word[upper_bound:(2*upper_bound + 1)]
18    18    
19def end(word):19def end(word):
20    length = len(word)20    length = len(word)
21    upper_bound = length // 321    upper_bound = length // 3
22    if length % 3 == 0:22    if length % 3 == 0:
23        return word[(upper_bound*2):]23        return word[(upper_bound*2):]
24    elif length % 3 == 2:24    elif length % 3 == 2:
25        return word[(2*upper_bound + 1):]25        return word[(2*upper_bound + 1):]
26    elif length % 3 == 1:26    elif length % 3 == 1:
27        return word[(2 * upper_bound + 1):]27        return word[(2 * upper_bound + 1):]
28    28    
29def split_word(word):29def split_word(word):
30    return beginning(word), middle(word), end(word)30    return beginning(word), middle(word), end(word)
3131
32def split_sentence(sentence):32def split_sentence(sentence):
33    my_list = []33    my_list = []
34    list_from_sentence = sentence.split()34    list_from_sentence = sentence.split()
35    for word in list_from_sentence:35    for word in list_from_sentence:
36        my_list.append(split_word(word))36        my_list.append(split_word(word))
37    return my_list37    return my_list
t38 t
39print(split_sentence('Kазвам се Джон Сноу'))
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)
n3    upperBound = length // 3n3    upper_bound = length // 3
4    if length % 3 == 0 or length % 3 == 1:4    if length % 3 == 0 or length % 3 == 1:
n5        return word[0:upperBound]n5        return word[:upper_bound]
6    elif length % 3 == 2:6    elif length % 3 == 2:
n7        return word[0:(upperBound + 1)]n7        return word[:(upper_bound + 1)]
88
9def middle(word):9def middle(word):
10    length = len(word)10    length = len(word)
n11    upperBound = length // 3n11    upper_bound = length // 3
12    if length % 3 == 0:12    if length % 3 == 0:
n13        return word[upperBound:(upperBound*2)]n13        return word[upper_bound:(upper_bound*2)]
14    elif length % 3 == 2:14    elif length % 3 == 2:
n15        return word[upperBound+1:(2*upperBound + 1)]n15        return word[upper_bound+1:(2*upper_bound + 1)]
16    elif length % 3 == 1:16    elif length % 3 == 1:
n17        return word[upperBound:(2*upperBound + 1)]n17        return word[upper_bound:(2*upper_bound + 1)]
18    18    
19def end(word):19def end(word):
20    length = len(word)20    length = len(word)
n21    upperBound = length // 3n21    upper_bound = length // 3
22    if length % 3 == 0:22    if length % 3 == 0:
n23        return word[(upperBound*2):length]n23        return word[(upper_bound*2):]
24    elif length % 3 == 2:24    elif length % 3 == 2:
n25        return word[(2*upperBound + 1):length]n25        return word[(2*upper_bound + 1):]
26    elif length % 3 == 1:26    elif length % 3 == 1:
n27        return word[(2 * upperBound + 1):length]n27        return word[(2 * upper_bound + 1):]
28    28    
n29def make_tuple(word):n29def split_word(word):
30    return beginning(word), middle(word), end(word)30    return beginning(word), middle(word), end(word)
3131
32def split_sentence(sentence):32def split_sentence(sentence):
33    my_list = []33    my_list = []
34    list_from_sentence = sentence.split()34    list_from_sentence = sentence.split()
n35    for i in range(0, len(list_from_sentence)):n35    for word in list_from_sentence:
36        my_list.append(make_tuple(list_from_sentence[i]))36        my_list.append(split_word(word))
37    return my_list37    return my_list
tt38 
39print(split_sentence('Kазвам се Джон Сноу'))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op