Домашни > Man who speaks the ends of words > Решения > Решението на Цветомир Гълъбов

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

7 точки общо

10 успешни теста
2 неуспешни теста
Код

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

[('ка', 'зв', 'ам'), ('с', '', 'е'), ('Д', 'жо', 'н'), ('С', 'но', 'у')]
.F....F.....
======================================================================
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: [('Зд[50 chars], 'е'), ('м', '', 'и'), ('', 'е', 'е'), ('отв', 'ертк', 'ата')] != [('Зд[50 chars], 'е'), ('м', '', 'и'), ('', 'е', ''), ('отв', 'ертк', 'ата')]

First differing element 4:
('', 'е', 'е')
('', 'е', '')

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

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

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

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

FAILED (failures=2)

Дискусия
Георги Кунчев
17.10.2023 18:15

Махаме една точка, заради неспазения `snake_case`.
История

f1def beginning(word):f1def beginning(word):
n2    wordlength = len(word)n2    wordLength = len(word)
3    lettersIn = 03    lettersIn = 0
n4    if wordlength % 3 == 0:n4    if wordLength % 3 == 0:
5        lettersIn = len(word) // 35        lettersIn = len(word) // 3
n6    elif wordlength % 3 == 2:n6    elif wordLength % 3 == 2:
7        lettersIn = len(word) // 3 + 17        lettersIn = len(word) // 3 + 1
8    else:8    else:
9        lettersIn = len(word) // 39        lettersIn = len(word) // 3
10    return word[:lettersIn]10    return word[:lettersIn]
1111
1212
13def middle(word):13def middle(word):
n14    wordlength = len(word)n14    wordLength = len(word)
15    lettersIn = 015    lettersIn = 0
16    FromIndx = 016    FromIndx = 0
n17    if wordlength % 3 == 0:n17    if wordLength % 3 == 0:
18        FromIndx = wordlength // 318        FromIndx = wordLength // 3
19        lettersIn = len(word) // 319        lettersIn = len(word) // 3
n20    elif wordlength % 3 == 2:n20    elif wordLength % 3 == 2:
21        FromIndx = wordlength // 3 + 121        FromIndx = wordLength // 3 + 1
22        lettersIn = len(word) // 322        lettersIn = len(word) // 3
23    else:23    else:
n24        FromIndx = wordlength // 3n24        FromIndx = wordLength // 3
25        lettersIn = len(word) // 3 + 125        lettersIn = len(word) // 3 + 1
26    return word[FromIndx : FromIndx + lettersIn]26    return word[FromIndx : FromIndx + lettersIn]
2727
2828
29def end(word):29def end(word):
n30    wordlength = len(word)n30    wordLength = len(word)
31    lettersIn = 031    lettersIn = 0
n32    if wordlength % 3 == 0:n32    if wordLength % 3 == 0:
33        lettersIn = len(word) // 333        lettersIn = len(word) // 3
t34    elif wordlength % 3 == 2:t34    elif wordLength % 3 == 2:
35        lettersIn = len(word) // 3 + 135        lettersIn = len(word) // 3 + 1
36    else:36    else:
37        lettersIn = len(word) // 337        lettersIn = len(word) // 3
38    return word[-lettersIn::1]38    return word[-lettersIn::1]
3939
4040
41def split_sentence(sentence):41def split_sentence(sentence):
42    words = sentence.split()42    words = sentence.split()
43    result = []43    result = []
44    for word in words:44    for word in words:
45        result.append((beginning(word), middle(word), end(word)))45        result.append((beginning(word), middle(word), end(word)))
46    return result46    return result
4747
4848
49print(split_sentence("казвам се Джон Сноу"))49print(split_sentence("казвам се Джон Сноу"))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    wordlength = len(word)2    wordlength = len(word)
3    lettersIn = 03    lettersIn = 0
4    if wordlength % 3 == 0:4    if wordlength % 3 == 0:
5        lettersIn = len(word) // 35        lettersIn = len(word) // 3
6    elif wordlength % 3 == 2:6    elif wordlength % 3 == 2:
7        lettersIn = len(word) // 3 + 17        lettersIn = len(word) // 3 + 1
8    else:8    else:
9        lettersIn = len(word) // 39        lettersIn = len(word) // 3
10    return word[:lettersIn]10    return word[:lettersIn]
1111
1212
13def middle(word):13def middle(word):
14    wordlength = len(word)14    wordlength = len(word)
15    lettersIn = 015    lettersIn = 0
16    FromIndx = 016    FromIndx = 0
17    if wordlength % 3 == 0:17    if wordlength % 3 == 0:
18        FromIndx = wordlength // 318        FromIndx = wordlength // 3
19        lettersIn = len(word) // 319        lettersIn = len(word) // 3
20    elif wordlength % 3 == 2:20    elif wordlength % 3 == 2:
21        FromIndx = wordlength // 3 + 121        FromIndx = wordlength // 3 + 1
22        lettersIn = len(word) // 322        lettersIn = len(word) // 3
23    else:23    else:
24        FromIndx = wordlength // 324        FromIndx = wordlength // 3
25        lettersIn = len(word) // 3 + 125        lettersIn = len(word) // 3 + 1
26    return word[FromIndx : FromIndx + lettersIn]26    return word[FromIndx : FromIndx + lettersIn]
2727
2828
29def end(word):29def end(word):
30    wordlength = len(word)30    wordlength = len(word)
31    lettersIn = 031    lettersIn = 0
32    if wordlength % 3 == 0:32    if wordlength % 3 == 0:
33        lettersIn = len(word) // 333        lettersIn = len(word) // 3
34    elif wordlength % 3 == 2:34    elif wordlength % 3 == 2:
35        lettersIn = len(word) // 3 + 135        lettersIn = len(word) // 3 + 1
36    else:36    else:
37        lettersIn = len(word) // 337        lettersIn = len(word) // 3
38    return word[-lettersIn::1]38    return word[-lettersIn::1]
3939
4040
t41def split_sentence(sentance):t41def split_sentence(sentence):
42    words = sentance.split()42    words = sentence.split()
43    result = []43    result = []
44    for word in words:44    for word in words:
45        result.append((beginning(word), middle(word), end(word)))45        result.append((beginning(word), middle(word), end(word)))
46    return result46    return result
4747
4848
49print(split_sentence("казвам се Джон Сноу"))49print(split_sentence("казвам се Джон Сноу"))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    wordlength = len(word)2    wordlength = len(word)
3    lettersIn = 03    lettersIn = 0
4    if wordlength % 3 == 0:4    if wordlength % 3 == 0:
5        lettersIn = len(word) // 35        lettersIn = len(word) // 3
6    elif wordlength % 3 == 2:6    elif wordlength % 3 == 2:
7        lettersIn = len(word) // 3 + 17        lettersIn = len(word) // 3 + 1
8    else:8    else:
9        lettersIn = len(word) // 39        lettersIn = len(word) // 3
n10    return word[: int(lettersIn)]n10    return word[:lettersIn]
1111
1212
13def middle(word):13def middle(word):
14    wordlength = len(word)14    wordlength = len(word)
15    lettersIn = 015    lettersIn = 0
16    FromIndx = 016    FromIndx = 0
17    if wordlength % 3 == 0:17    if wordlength % 3 == 0:
18        FromIndx = wordlength // 318        FromIndx = wordlength // 3
19        lettersIn = len(word) // 319        lettersIn = len(word) // 3
20    elif wordlength % 3 == 2:20    elif wordlength % 3 == 2:
21        FromIndx = wordlength // 3 + 121        FromIndx = wordlength // 3 + 1
22        lettersIn = len(word) // 322        lettersIn = len(word) // 3
23    else:23    else:
24        FromIndx = wordlength // 324        FromIndx = wordlength // 3
25        lettersIn = len(word) // 3 + 125        lettersIn = len(word) // 3 + 1
n26    return word[int(FromIndx) : int(FromIndx) + int(lettersIn)]n26    return word[FromIndx : FromIndx + lettersIn]
2727
2828
29def end(word):29def end(word):
30    wordlength = len(word)30    wordlength = len(word)
31    lettersIn = 031    lettersIn = 0
32    if wordlength % 3 == 0:32    if wordlength % 3 == 0:
33        lettersIn = len(word) // 333        lettersIn = len(word) // 3
34    elif wordlength % 3 == 2:34    elif wordlength % 3 == 2:
35        lettersIn = len(word) // 3 + 135        lettersIn = len(word) // 3 + 1
36    else:36    else:
37        lettersIn = len(word) // 337        lettersIn = len(word) // 3
n38    return word[-int(lettersIn:: 1]n38    return word[-lettersIn::1]
3939
4040
41def split_sentence(sentance):41def split_sentence(sentance):
n42    words = str(sentance).split()n42    words = sentance.split()
43    result = []43    result = []
44    for word in words:44    for word in words:
45        result.append((beginning(word), middle(word), end(word)))45        result.append((beginning(word), middle(word), end(word)))
46    return result46    return result
tt47 
48 
49print(split_sentence("казвам се Джон Сноу"))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    wordlength = len(word)2    wordlength = len(word)
3    lettersIn = 03    lettersIn = 0
4    if wordlength % 3 == 0:4    if wordlength % 3 == 0:
5        lettersIn = len(word) // 35        lettersIn = len(word) // 3
6    elif wordlength % 3 == 2:6    elif wordlength % 3 == 2:
7        lettersIn = len(word) // 3 + 17        lettersIn = len(word) // 3 + 1
8    else:8    else:
9        lettersIn = len(word) // 39        lettersIn = len(word) // 3
10    return word[: int(lettersIn)]10    return word[: int(lettersIn)]
1111
1212
13def middle(word):13def middle(word):
14    wordlength = len(word)14    wordlength = len(word)
15    lettersIn = 015    lettersIn = 0
16    FromIndx = 016    FromIndx = 0
17    if wordlength % 3 == 0:17    if wordlength % 3 == 0:
18        FromIndx = wordlength // 318        FromIndx = wordlength // 3
19        lettersIn = len(word) // 319        lettersIn = len(word) // 3
20    elif wordlength % 3 == 2:20    elif wordlength % 3 == 2:
21        FromIndx = wordlength // 3 + 121        FromIndx = wordlength // 3 + 1
22        lettersIn = len(word) // 322        lettersIn = len(word) // 3
23    else:23    else:
24        FromIndx = wordlength // 324        FromIndx = wordlength // 3
25        lettersIn = len(word) // 3 + 125        lettersIn = len(word) // 3 + 1
26    return word[int(FromIndx) : int(FromIndx) + int(lettersIn)]26    return word[int(FromIndx) : int(FromIndx) + int(lettersIn)]
2727
2828
29def end(word):29def end(word):
30    wordlength = len(word)30    wordlength = len(word)
31    lettersIn = 031    lettersIn = 0
32    if wordlength % 3 == 0:32    if wordlength % 3 == 0:
33        lettersIn = len(word) // 333        lettersIn = len(word) // 3
34    elif wordlength % 3 == 2:34    elif wordlength % 3 == 2:
35        lettersIn = len(word) // 3 + 135        lettersIn = len(word) // 3 + 1
36    else:36    else:
37        lettersIn = len(word) // 337        lettersIn = len(word) // 3
38    return word[-int(lettersIn) :: 1]38    return word[-int(lettersIn) :: 1]
3939
4040
t41def split_sentance(sentance):t41def split_sentence(sentance):
42    words = str(sentance).split()42    words = str(sentance).split()
43    result = []43    result = []
44    for word in words:44    for word in words:
45        result.append((beginning(word), middle(word), end(word)))45        result.append((beginning(word), middle(word), end(word)))
46    return result46    return result
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op