Домашни > Man who speaks the ends of words > Решения > Решението на Десислава Белчева

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

7 точки общо

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

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

.F....FFF...
======================================================================
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: Lists differ: [('Зд[18 chars] ('мом', 'че', 'та'), ('къ', 'д', 'е'), ('ми',[43 chars]та')] != [('Зд[18 chars] ('мо', 'мче', 'та'), ('к', 'ъд', 'е'), ('м', [43 chars]та')]

First differing element 1:
('мом', 'че', 'та')
('мо', 'мче', 'та')

[('Здр', 'аве', 'йте'),
- ('мом', 'че', 'та'),
? -

+ ('мо', 'мче', 'та'),
? +

- ('къ', 'д', 'е'),
? -

+ ('к', 'ъд', 'е'),
? +

- ('ми', '', ''),
? -

+ ('м', '', 'и'),
? +

- ('е', '', ''),
+ ('', 'е', ''),
- ('отве', 'ртк', 'ата')]
? -

+ ('отв', 'ертк', 'ата')]
? +

======================================================================
FAIL: test_one_letter (test.TestWords)
Test with single letter.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 44, in test_one_letter
self.assertEqual(beginning('#'), '')
AssertionError: '#' != ''
- #
+

======================================================================
FAIL: test_remainder_1 (test.TestWords)
Test splitting a word that has a remainder of 1 when divided by 3.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 31, in test_remainder_1
self.assertEqual(beginning(word), 'ааа')
AssertionError: 'аааб' != 'ааа'
- аааб
? -
+ ааа

======================================================================
FAIL: test_remainder_2 (test.TestWords)
Test splitting a word that has a remainder of 2 when divided by 3.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 38, in test_remainder_2
self.assertEqual(beginning(word), '🐍🐍🐍')
AssertionError: '🐍🐍🐍🙏' != '🐍🐍🐍'
- 🐍🐍🐍🙏
? -
+ 🐍🐍🐍

----------------------------------------------------------------------
Ran 12 tests in 0.002s

FAILED (failures=4)

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