Домашни > Man who speaks the ends of words > Решения > Решението на Пресиан Андрейчев

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

9 точки общо

11 успешни теста
1 неуспешни теста
Код

 1def get_word_size(word):
 2    try:
 3        word_length = len(word)
 4        return word_length
 5    except TypeError:
 6        return 
 7    
 8
 9def beginning(word):
10    word_length = get_word_size(word)
11    if word_length:
12        split = int(word_length / 3)
13        if word_length % 3 == 0 or word_length % 3 == 1:
14            return word[0:split]
15        else:
16            return word[0:split+1]
17
18
19def middle(word):
20    word_length = get_word_size(word)
21    if word_length:
22        split = int(word_length / 3)
23        if word_length % 3 == 0:
24            return word[split:split*2]
25        elif word_length % 3 == 1:
26            return word[split:split*2+1]
27        else:
28            return word[split+1:split*2+1]
29
30
31def end(word):
32    word_length = get_word_size(word)
33    if word_length:
34        split = int(word_length / 3)
35        if word_length % 3 == 0:
36            return word[split*2:]
37        else:
38            return word[split*2+1:]
39    
40
41def split_sentence(sentence):
42    list_sentence = []
43    sentence = sentence.split()
44    for i in sentence:
45        list_sentence.append((beginning(i), middle(i), end(i)))
46    return list_sentence

...F........
======================================================================
FAIL: test_empty_input (test.TestWords)
Test with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_empty_input
self.assertEqual(beginning(''), '')
AssertionError: None != ''

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

FAILED (failures=1)

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

f1def get_word_size(word):f1def get_word_size(word):
2    try:2    try:
3        word_length = len(word)3        word_length = len(word)
4        return word_length4        return word_length
5    except TypeError:5    except TypeError:
n6        return Falsen6        return 
7    7    
88
9def beginning(word):9def beginning(word):
10    word_length = get_word_size(word)10    word_length = get_word_size(word)
11    if word_length:11    if word_length:
12        split = int(word_length / 3)12        split = int(word_length / 3)
n13        if word_length % 3 == 0:n13        if word_length % 3 == 0 or word_length % 3 == 1:
14            return word[0:split]
15        elif word_length % 3 == 1:
16            return word[0:split]14            return word[0:split]
17        else:15        else:
18            return word[0:split+1]16            return word[0:split+1]
n19    else:n
20        return "Invalid"
2117
2218
23def middle(word):19def middle(word):
24    word_length = get_word_size(word)20    word_length = get_word_size(word)
25    if word_length:21    if word_length:
26        split = int(word_length / 3)22        split = int(word_length / 3)
27        if word_length % 3 == 0:23        if word_length % 3 == 0:
28            return word[split:split*2]24            return word[split:split*2]
29        elif word_length % 3 == 1:25        elif word_length % 3 == 1:
30            return word[split:split*2+1]26            return word[split:split*2+1]
31        else:27        else:
32            return word[split+1:split*2+1]28            return word[split+1:split*2+1]
n33    else:n
34        return "Invalid"
3529
3630
37def end(word):31def end(word):
38    word_length = get_word_size(word)32    word_length = get_word_size(word)
39    if word_length:33    if word_length:
40        split = int(word_length / 3)34        split = int(word_length / 3)
41        if word_length % 3 == 0:35        if word_length % 3 == 0:
42            return word[split*2:]36            return word[split*2:]
n43        elif word_length % 3 == 1:n
44            return word[split*2+1:]
45        else:37        else:
46            return word[split*2+1:]38            return word[split*2+1:]
n47    else:n39    
48        return "Invalid"
49 
5040
51def split_sentence(sentence):41def split_sentence(sentence):
52    list_sentence = []42    list_sentence = []
53    sentence = sentence.split()43    sentence = sentence.split()
n54    print(sentence)n
55    for i in sentence:44    for i in sentence:
n56        print(i)n
57        list_sentence.append((beginning(i), middle(i), end(i)))45        list_sentence.append((beginning(i), middle(i), end(i)))
58    return list_sentence46    return list_sentence
5947
t60 t
61'''
62print(beginning('шах'))
63print(middle('шах'))
64print(end('шах'))
65print(beginning('Враца'))
66print(middle('Враца'))
67print(end('Враца'))
68print(beginning('барабани'))
69print(middle('барабани'))
70print(end('барабани'))
71print(beginning('цици'))
72print(middle('цици'))
73print(end('цици'))
74print(beginning('домашни'))
75print(middle('домашни'))
76print(end('домашни'))
77print(split_sentence('Kазвам се Джон Сноу'))
78'''
79 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op