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

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

8 точки общо

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

 1def beginning(word):
 2    length = len(word)
 3    if length % 3 == 0:
 4       return  word[:length//3]
 5    elif length % 3 == 1:
 6        return word[:length//3]
 7    else:
 8        return word[:length//3+1]
 9
10    
11def middle(word):
12    length = len(word)
13    if length % 3 == 0:
14        return word[length//3:length*2//3]
15    elif length % 3 == 1:
16        return word[length//3:length*2//3+1]
17    else:
18        return word[length//3+1:length*2//3]
19        
20    
21def end(word):
22    length = len(word)
23    if length % 3 == 0:
24        return word[length*2//3:]
25    elif length % 3 == 1 :
26        return word[length*2//3+1:]
27    else:
28        return word[length*2//3:]
29    
30
31def split_sentence(sentence):
32    words = sentence.split ()
33    for word in words:
34        beg_word = beginning(word)
35        mid_word = middle(word)
36        end_word = end(word)
37        print(beg_word, mid_word , end_word)
38        
39
40
41
42
43split_sentence('Kазвам се Джон Сноу')
44
45
46
47
48
49        

Kа зв ам
с е
Д жо н
С но у
FF
Stdout:
Здр аве йте
мо мче та
к ъд е
м и
е
отв ертк ата
F
Stdout:
a b c
a b c
a b c
.........
======================================================================
FAIL: test_empty_sentence (test.TestSentence)
Test with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 71, in test_empty_sentence
self.assertTrue(split_sentence('') in ([], [('', '', '')]))
AssertionError: False is not true

======================================================================
FAIL: test_mixed_sentence (test.TestSentence)
Test with mixed remainder input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 75, in test_mixed_sentence
self.assertEqual(split_sentence('Здравейте момчета къде ми е отвертката'),
AssertionError: None != [('Здр', 'аве', 'йте'), ('мо', 'мче', 'та[71 chars]та')]

Stdout:
Здр аве йте
мо мче та
к ъд е
м и
е
отв ертк ата

======================================================================
FAIL: test_simple_sentence (test.TestSentence)
Simple test for splitting a sentence into a list of split words.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 67, in test_simple_sentence
self.assertEqual(split_sentence('abc abc abc'), [('a', 'b', 'c')] * 3)
AssertionError: None != [('a', 'b', 'c'), ('a', 'b', 'c'), ('a', 'b', 'c')]

Stdout:
a b c
a b c
a b c

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

FAILED (failures=3)

Дискусия
История
Това решение има само една версия.