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

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

10 точки общо

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

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

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

OK

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

f1def beginning(word):f1def beginning(word):
n2    remainder = len(word)%3n2    remainder = len(word) % 3
3    part = len(word)//33    part = len(word) // 3
4    if remainder == 0:4    if remainder == 0:
5        return word[:part]5        return word[:part]
6    elif remainder == 2:6    elif remainder == 2:
n7        return word[:part+1]n7        return word[:part + 1]
8    return word[:part]8    return word[:part]
9        9        
10def middle(word):10def middle(word):
n11    remainder = len(word)%3n11    remainder = len(word) % 3
12    part = len(word)//312    part = len(word) // 3
13    if remainder == 0:13    if remainder == 0:
n14        return word[part:2*part]n14        return word[part:2 * part]
15    elif remainder == 2:15    elif remainder == 2:
n16        return word[part+1:2*part+1]n16        return word[part + 1:2 * part + 1]
17    return word[part:2*part+1]17    return word[part:2 * part + 1]
1818
19def end(word):19def end(word):
n20    remainder = len(word)%3n20    remainder = len(word) % 3
21    part = len(word)//321    part = len(word) // 3
22    if remainder == 0:22    if remainder == 0:
n23        return word[2*part:]n23        return word[2 * part:]
24    elif remainder == 2:24    elif remainder == 2:
n25        return word[2*part+1:]n25        return word[2 * part + 1:]
26    return word[2*part+1:]26    return word[2 * part + 1:]
2727
n28def make_tuple (word):n28def separate_word(word):
29    return (beginning(word), middle(word), end(word))29    return (beginning(word), middle(word), end(word))
3030
31def split_sentence(sentence):31def split_sentence(sentence):
n32    word = ''n32    return list(map(separate_word, sentence.split()))
33    words = []
34    for letter in sentence:
35        if letter != ' ':
36            word += letter
37        else:
38            words.append(word)
39            word = ''
40    words.append(word)
41    return list(map(make_tuple, words))
4233
tt34 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    remainder = len(word)%32    remainder = len(word)%3
3    part = len(word)//33    part = len(word)//3
4    if remainder == 0:4    if remainder == 0:
5        return word[:part]5        return word[:part]
6    elif remainder == 2:6    elif remainder == 2:
7        return word[:part+1]7        return word[:part+1]
8    return word[:part]8    return word[:part]
9        9        
10def middle(word):10def middle(word):
11    remainder = len(word)%311    remainder = len(word)%3
12    part = len(word)//312    part = len(word)//3
13    if remainder == 0:13    if remainder == 0:
14        return word[part:2*part]14        return word[part:2*part]
15    elif remainder == 2:15    elif remainder == 2:
16        return word[part+1:2*part+1]16        return word[part+1:2*part+1]
17    return word[part:2*part+1]17    return word[part:2*part+1]
1818
19def end(word):19def end(word):
20    remainder = len(word)%320    remainder = len(word)%3
21    part = len(word)//321    part = len(word)//3
22    if remainder == 0:22    if remainder == 0:
23        return word[2*part:]23        return word[2*part:]
24    elif remainder == 2:24    elif remainder == 2:
25        return word[2*part+1:]25        return word[2*part+1:]
26    return word[2*part+1:]26    return word[2*part+1:]
2727
28def make_tuple (word):28def make_tuple (word):
29    return (beginning(word), middle(word), end(word))29    return (beginning(word), middle(word), end(word))
3030
31def split_sentence(sentence):31def split_sentence(sentence):
32    word = ''32    word = ''
33    words = []33    words = []
34    for letter in sentence:34    for letter in sentence:
35        if letter != ' ':35        if letter != ' ':
36            word += letter36            word += letter
37        else:37        else:
38            words.append(word)38            words.append(word)
39            word = ''39            word = ''
nn40    words.append(word)
40    return list(map(make_tuple, words))41    return list(map(make_tuple, words))
t41    t42 
42word = 'qwew'
43part = len(word)//3
44print(make_tuple(word))
45print (len(word))
46print (part)
47sentence = 'Kазвам се Джон Сноу'
48print (split_sentence(sentence))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1def beginning(word):t1def beginning(word):
2    remainder = len(word)%32    remainder = len(word)%3
3    part = len(word)//33    part = len(word)//3
4    if remainder == 0:4    if remainder == 0:
5        return word[:part]5        return word[:part]
6    elif remainder == 2:6    elif remainder == 2:
7        return word[:part+1]7        return word[:part+1]
8    return word[:part]8    return word[:part]
9        9        
10def middle(word):10def middle(word):
11    remainder = len(word)%311    remainder = len(word)%3
12    part = len(word)//312    part = len(word)//3
13    if remainder == 0:13    if remainder == 0:
14        return word[part:2*part]14        return word[part:2*part]
15    elif remainder == 2:15    elif remainder == 2:
16        return word[part+1:2*part+1]16        return word[part+1:2*part+1]
17    return word[part:2*part+1]17    return word[part:2*part+1]
1818
19def end(word):19def end(word):
20    remainder = len(word)%320    remainder = len(word)%3
21    part = len(word)//321    part = len(word)//3
22    if remainder == 0:22    if remainder == 0:
23        return word[2*part:]23        return word[2*part:]
24    elif remainder == 2:24    elif remainder == 2:
25        return word[2*part+1:]25        return word[2*part+1:]
26    return word[2*part+1:]26    return word[2*part+1:]
2727
28def make_tuple (word):28def make_tuple (word):
29    return (beginning(word), middle(word), end(word))29    return (beginning(word), middle(word), end(word))
3030
31def split_sentence(sentence):31def split_sentence(sentence):
32    word = ''32    word = ''
33    words = []33    words = []
34    for letter in sentence:34    for letter in sentence:
35        if letter != ' ':35        if letter != ' ':
36            word += letter36            word += letter
37        else:37        else:
38            words.append(word)38            words.append(word)
39            word = ''39            word = ''
40    return list(map(make_tuple, words))40    return list(map(make_tuple, words))
41    41    
42word = 'qwew'42word = 'qwew'
43part = len(word)//343part = len(word)//3
44print(make_tuple(word))44print(make_tuple(word))
45print (len(word))45print (len(word))
46print (part)46print (part)
47sentence = 'Kазвам се Джон Сноу'47sentence = 'Kазвам се Джон Сноу'
48print (split_sentence(sentence))48print (split_sentence(sentence))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op