1def beginning(word):
2 word_length = len(word)
3 value_remaining = word_length % 3
4
5 if value_remaining == 0:
6 word_length_to_take = int(word_length / 3)
7 return (word[0:word_length_to_take])
8 elif value_remaining == 1:
9 word_length_to_take = int(((word_length)-1) / 3)
10 return (word[0:word_length_to_take])
11 else:
12 word_length_to_take = 0
13 if (word_length - 1) % 2 == 0:
14 word_length_to_take = int((word_length - 1) / 2)
15 else:
16 word_length_to_take = int((word_length - 2) / 2)
17
18 return word[0:word_length_to_take]
19
20def end(word):
21 word_length = len(word)
22 value_remaining = word_length % 3
23
24 if value_remaining == 0:
25 word_length_to_take = int(word_length / 3)
26 return word[word_length - word_length_to_take : word_length]
27 elif value_remaining == 1:
28 word_length_to_take = int(((word_length)-1) / 3)
29 return word[word_length - word_length_to_take : word_length]
30 else:
31 word_length_to_take = 0
32 if (word_length - 1) % 2 == 0:
33 word_length_to_take = int((word_length - 1) / 2)
34 else:
35 word_length_to_take = int((word_length - 2) / 2)
36
37 return word[word_length - word_length_to_take : word_length]
38
39def middle(word):
40 word_length = len(word)
41 value_remaining = word_length % 3
42
43 if value_remaining == 0:
44 word_length_to_take = int(word_length / 3)
45 return (word[word_length_to_take : word_length - word_length_to_take])
46 elif value_remaining == 1:
47 word_length_to_take = int(((word_length)-1) / 3)
48 return (word[word_length_to_take : word_length - word_length_to_take])
49 else:
50 word_length_to_take = 0
51 if (word_length - 1) % 2 == 0:
52 word_length_to_take = int((word_length - 1) / 2)
53 else:
54 word_length_to_take = int((word_length - 2) / 2)
55
56 return word[word_length_to_take : word_length - word_length_to_take]
57
58def split_sentence(sentece):
59 splited_sentence = sentece.split(' ')
60 result = []
61 for word in splited_sentence:
62 beginning_of_word = beginning(word)
63 middle_of_word = middle(word)
64 end_of_word = end(word)
65 result.append((beginning_of_word,middle_of_word,end_of_word))
66
67 return result
68
69print(split_sentence('Продаваме лиофилизиран ананас'))
[('Про', 'дав', 'аме'), ('лиоф', 'илиз', 'иран'), ('ан', 'ан', 'ас')]
.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: [('Зд[49 chars]', 'е'), ('', 'ми', ''), ('', 'е', ''), ('отв', 'ертк', 'ата')] != [('Зд[49 chars]', 'е'), ('м', '', 'и'), ('', 'е', ''), ('отв', 'ертк', 'ата')]
First differing element 3:
('', 'ми', '')
('м', '', 'и')
[('Здр', 'аве', 'йте'),
('мо', 'мче', 'та'),
('к', 'ъд', 'е'),
- ('', 'ми', ''),
+ ('м', '', 'и'),
('', 'е', ''),
('отв', 'ертк', 'ата')]
----------------------------------------------------------------------
Ran 12 tests in 0.001s
FAILED (failures=1)
Адем Црънчалиев
17.10.2023 10:12Когато премахна от [0:length] 0-лата, не ми връща правилен резултат.
|
Виктор Бечев
17.10.2023 09:30Две генерални забележки:
- Навсякъде си написал "lenght", думата е "length".
- Всичките условия и изчисления правят "алгоритъма" доста трудно-проследим. Вероятно ще сработи, не държа да го променяш с риск да стане по-неработещо, просто FYI.
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | word_length = len(word) | 2 | word_length = len(word) | ||
3 | value_remaining = word_length % 3 | 3 | value_remaining = word_length % 3 | ||
4 | 4 | ||||
5 | if value_remaining == 0: | 5 | if value_remaining == 0: | ||
6 | word_length_to_take = int(word_length / 3) | 6 | word_length_to_take = int(word_length / 3) | ||
n | 7 | return (word[word_length_to_take]) | n | 7 | return (word[0:word_length_to_take]) |
8 | elif value_remaining == 1: | 8 | elif value_remaining == 1: | ||
9 | word_length_to_take = int(((word_length)-1) / 3) | 9 | word_length_to_take = int(((word_length)-1) / 3) | ||
n | 10 | return (word[word_length_to_take]) | n | 10 | return (word[0:word_length_to_take]) |
11 | else: | 11 | else: | ||
12 | word_length_to_take = 0 | 12 | word_length_to_take = 0 | ||
13 | if (word_length - 1) % 2 == 0: | 13 | if (word_length - 1) % 2 == 0: | ||
14 | word_length_to_take = int((word_length - 1) / 2) | 14 | word_length_to_take = int((word_length - 1) / 2) | ||
15 | else: | 15 | else: | ||
16 | word_length_to_take = int((word_length - 2) / 2) | 16 | word_length_to_take = int((word_length - 2) / 2) | ||
17 | 17 | ||||
n | 18 | return word[word_length_to_take] | n | 18 | return word[0:word_length_to_take] |
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
21 | word_length = len(word) | 21 | word_length = len(word) | ||
22 | value_remaining = word_length % 3 | 22 | value_remaining = word_length % 3 | ||
23 | 23 | ||||
24 | if value_remaining == 0: | 24 | if value_remaining == 0: | ||
25 | word_length_to_take = int(word_length / 3) | 25 | word_length_to_take = int(word_length / 3) | ||
26 | return word[word_length - word_length_to_take : word_length] | 26 | return word[word_length - word_length_to_take : word_length] | ||
27 | elif value_remaining == 1: | 27 | elif value_remaining == 1: | ||
28 | word_length_to_take = int(((word_length)-1) / 3) | 28 | word_length_to_take = int(((word_length)-1) / 3) | ||
29 | return word[word_length - word_length_to_take : word_length] | 29 | return word[word_length - word_length_to_take : word_length] | ||
30 | else: | 30 | else: | ||
31 | word_length_to_take = 0 | 31 | word_length_to_take = 0 | ||
32 | if (word_length - 1) % 2 == 0: | 32 | if (word_length - 1) % 2 == 0: | ||
33 | word_length_to_take = int((word_length - 1) / 2) | 33 | word_length_to_take = int((word_length - 1) / 2) | ||
34 | else: | 34 | else: | ||
35 | word_length_to_take = int((word_length - 2) / 2) | 35 | word_length_to_take = int((word_length - 2) / 2) | ||
36 | 36 | ||||
37 | return word[word_length - word_length_to_take : word_length] | 37 | return word[word_length - word_length_to_take : word_length] | ||
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
40 | word_length = len(word) | 40 | word_length = len(word) | ||
41 | value_remaining = word_length % 3 | 41 | value_remaining = word_length % 3 | ||
42 | 42 | ||||
43 | if value_remaining == 0: | 43 | if value_remaining == 0: | ||
44 | word_length_to_take = int(word_length / 3) | 44 | word_length_to_take = int(word_length / 3) | ||
45 | return (word[word_length_to_take : word_length - word_length_to_take]) | 45 | return (word[word_length_to_take : word_length - word_length_to_take]) | ||
46 | elif value_remaining == 1: | 46 | elif value_remaining == 1: | ||
47 | word_length_to_take = int(((word_length)-1) / 3) | 47 | word_length_to_take = int(((word_length)-1) / 3) | ||
48 | return (word[word_length_to_take : word_length - word_length_to_take]) | 48 | return (word[word_length_to_take : word_length - word_length_to_take]) | ||
49 | else: | 49 | else: | ||
50 | word_length_to_take = 0 | 50 | word_length_to_take = 0 | ||
51 | if (word_length - 1) % 2 == 0: | 51 | if (word_length - 1) % 2 == 0: | ||
52 | word_length_to_take = int((word_length - 1) / 2) | 52 | word_length_to_take = int((word_length - 1) / 2) | ||
53 | else: | 53 | else: | ||
54 | word_length_to_take = int((word_length - 2) / 2) | 54 | word_length_to_take = int((word_length - 2) / 2) | ||
55 | 55 | ||||
56 | return word[word_length_to_take : word_length - word_length_to_take] | 56 | return word[word_length_to_take : word_length - word_length_to_take] | ||
57 | 57 | ||||
58 | def split_sentence(sentece): | 58 | def split_sentence(sentece): | ||
n | 59 | splited_sentence = sentece.split() | n | 59 | splited_sentence = sentece.split(' ') |
60 | result = [] | 60 | result = [] | ||
61 | for word in splited_sentence: | 61 | for word in splited_sentence: | ||
62 | beginning_of_word = beginning(word) | 62 | beginning_of_word = beginning(word) | ||
63 | middle_of_word = middle(word) | 63 | middle_of_word = middle(word) | ||
64 | end_of_word = end(word) | 64 | end_of_word = end(word) | ||
65 | result.append((beginning_of_word,middle_of_word,end_of_word)) | 65 | result.append((beginning_of_word,middle_of_word,end_of_word)) | ||
66 | 66 | ||||
67 | return result | 67 | return result | ||
68 | 68 | ||||
t | t | 69 | print(split_sentence('Продаваме лиофилизиран ананас')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
n | 2 | wordLenght = len(word) | n | 2 | word_length = len(word) |
3 | valueRemaining = wordLenght % 3 | 3 | value_remaining = word_length % 3 | ||
4 | 4 | ||||
n | 5 | if valueRemaining == 0: | n | 5 | if value_remaining == 0: |
6 | wordLenghtToTake = int(wordLenght / 3) | 6 | word_length_to_take = int(word_length / 3) | ||
7 | return (word[0:wordLenghtToTake]) | 7 | return (word[word_length_to_take]) | ||
8 | elif valueRemaining == 1: | 8 | elif value_remaining == 1: | ||
9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 9 | word_length_to_take = int(((word_length)-1) / 3) | ||
10 | return (word[0:wordLenghtToTake]) | 10 | return (word[word_length_to_take]) | ||
11 | else: | 11 | else: | ||
n | 12 | wordLenghtToTake = 0 | n | 12 | word_length_to_take = 0 |
13 | if (wordLenght - 1) % 2 == 0: | 13 | if (word_length - 1) % 2 == 0: | ||
14 | wordLenghtToTake = int((wordLenght - 1) / 2) | 14 | word_length_to_take = int((word_length - 1) / 2) | ||
15 | else: | 15 | else: | ||
n | 16 | wordLenghtToTake = int((wordLenght - 2) / 2) | n | 16 | word_length_to_take = int((word_length - 2) / 2) |
17 | 17 | ||||
n | 18 | return (word[0:wordLenghtToTake]) | n | 18 | return word[word_length_to_take] |
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
n | 21 | wordLenght = len(word) | n | 21 | word_length = len(word) |
22 | valueRemaining = wordLenght % 3 | 22 | value_remaining = word_length % 3 | ||
23 | 23 | ||||
n | 24 | if valueRemaining == 0: | n | 24 | if value_remaining == 0: |
25 | wordLenghtToTake = int(wordLenght / 3) | 25 | word_length_to_take = int(word_length / 3) | ||
26 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | 26 | return word[word_length - word_length_to_take : word_length] | ||
27 | elif valueRemaining == 1: | 27 | elif value_remaining == 1: | ||
28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 28 | word_length_to_take = int(((word_length)-1) / 3) | ||
29 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | 29 | return word[word_length - word_length_to_take : word_length] | ||
30 | else: | 30 | else: | ||
n | 31 | wordLenghtToTake = 0 | n | 31 | word_length_to_take = 0 |
32 | if (wordLenght - 1) % 2 == 0: | 32 | if (word_length - 1) % 2 == 0: | ||
33 | wordLenghtToTake = int((wordLenght - 1) / 2) | 33 | word_length_to_take = int((word_length - 1) / 2) | ||
34 | else: | 34 | else: | ||
n | 35 | wordLenghtToTake = int((wordLenght - 2) / 2) | n | 35 | word_length_to_take = int((word_length - 2) / 2) |
36 | 36 | ||||
n | 37 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | n | 37 | return word[word_length - word_length_to_take : word_length] |
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
n | 40 | wordLenght = len(word) | n | 40 | word_length = len(word) |
41 | valueRemaining = wordLenght % 3 | 41 | value_remaining = word_length % 3 | ||
42 | 42 | ||||
n | 43 | if valueRemaining == 0: | n | 43 | if value_remaining == 0: |
44 | wordLenghtToTake = int(wordLenght / 3) | 44 | word_length_to_take = int(word_length / 3) | ||
45 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 45 | return (word[word_length_to_take : word_length - word_length_to_take]) | ||
46 | elif valueRemaining == 1: | 46 | elif value_remaining == 1: | ||
47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 47 | word_length_to_take = int(((word_length)-1) / 3) | ||
48 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 48 | return (word[word_length_to_take : word_length - word_length_to_take]) | ||
49 | else: | 49 | else: | ||
n | 50 | wordLenghtToTake = 0 | n | 50 | word_length_to_take = 0 |
51 | if (wordLenght - 1) % 2 == 0: | 51 | if (word_length - 1) % 2 == 0: | ||
52 | wordLenghtToTake = int((wordLenght - 1) / 2) | 52 | word_length_to_take = int((word_length - 1) / 2) | ||
53 | else: | 53 | else: | ||
n | 54 | wordLenghtToTake = int((wordLenght - 2) / 2) | n | 54 | word_length_to_take = int((word_length - 2) / 2) |
55 | 55 | ||||
n | 56 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | n | 56 | return word[word_length_to_take : word_length - word_length_to_take] |
57 | 57 | ||||
58 | def split_sentence(sentece): | 58 | def split_sentence(sentece): | ||
n | 59 | splitedSentence = sentece.split(' ') | n | 59 | splited_sentence = sentece.split() |
60 | result = [] | 60 | result = [] | ||
n | 61 | for word in splitedSentence: | n | 61 | for word in splited_sentence: |
62 | beginningOfWord = beginning(word) | 62 | beginning_of_word = beginning(word) | ||
63 | middleOfWord = middle(word) | 63 | middle_of_word = middle(word) | ||
64 | endOfWord = end(word) | 64 | end_of_word = end(word) | ||
65 | result.append((beginningOfWord,middleOfWord,endOfWord)) | 65 | result.append((beginning_of_word,middle_of_word,end_of_word)) | ||
66 | 66 | ||||
t | 67 | return (result) | t | 67 | return result |
68 | 68 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordLenght = len(word) | 2 | wordLenght = len(word) | ||
3 | valueRemaining = wordLenght % 3 | 3 | valueRemaining = wordLenght % 3 | ||
4 | 4 | ||||
5 | if valueRemaining == 0: | 5 | if valueRemaining == 0: | ||
6 | wordLenghtToTake = int(wordLenght / 3) | 6 | wordLenghtToTake = int(wordLenght / 3) | ||
7 | return (word[0:wordLenghtToTake]) | 7 | return (word[0:wordLenghtToTake]) | ||
8 | elif valueRemaining == 1: | 8 | elif valueRemaining == 1: | ||
9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
10 | return (word[0:wordLenghtToTake]) | 10 | return (word[0:wordLenghtToTake]) | ||
11 | else: | 11 | else: | ||
12 | wordLenghtToTake = 0 | 12 | wordLenghtToTake = 0 | ||
13 | if (wordLenght - 1) % 2 == 0: | 13 | if (wordLenght - 1) % 2 == 0: | ||
14 | wordLenghtToTake = int((wordLenght - 1) / 2) | 14 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
15 | else: | 15 | else: | ||
16 | wordLenghtToTake = int((wordLenght - 2) / 2) | 16 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
17 | 17 | ||||
18 | return (word[0:wordLenghtToTake]) | 18 | return (word[0:wordLenghtToTake]) | ||
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
21 | wordLenght = len(word) | 21 | wordLenght = len(word) | ||
22 | valueRemaining = wordLenght % 3 | 22 | valueRemaining = wordLenght % 3 | ||
23 | 23 | ||||
24 | if valueRemaining == 0: | 24 | if valueRemaining == 0: | ||
25 | wordLenghtToTake = int(wordLenght / 3) | 25 | wordLenghtToTake = int(wordLenght / 3) | ||
26 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | 26 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | ||
27 | elif valueRemaining == 1: | 27 | elif valueRemaining == 1: | ||
28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
29 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | 29 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | ||
30 | else: | 30 | else: | ||
31 | wordLenghtToTake = 0 | 31 | wordLenghtToTake = 0 | ||
32 | if (wordLenght - 1) % 2 == 0: | 32 | if (wordLenght - 1) % 2 == 0: | ||
33 | wordLenghtToTake = int((wordLenght - 1) / 2) | 33 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
34 | else: | 34 | else: | ||
35 | wordLenghtToTake = int((wordLenght - 2) / 2) | 35 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
36 | 36 | ||||
37 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | 37 | return (word[wordLenght - wordLenghtToTake : wordLenght]) | ||
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
40 | wordLenght = len(word) | 40 | wordLenght = len(word) | ||
41 | valueRemaining = wordLenght % 3 | 41 | valueRemaining = wordLenght % 3 | ||
42 | 42 | ||||
43 | if valueRemaining == 0: | 43 | if valueRemaining == 0: | ||
44 | wordLenghtToTake = int(wordLenght / 3) | 44 | wordLenghtToTake = int(wordLenght / 3) | ||
45 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 45 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
46 | elif valueRemaining == 1: | 46 | elif valueRemaining == 1: | ||
47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
48 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 48 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
49 | else: | 49 | else: | ||
50 | wordLenghtToTake = 0 | 50 | wordLenghtToTake = 0 | ||
51 | if (wordLenght - 1) % 2 == 0: | 51 | if (wordLenght - 1) % 2 == 0: | ||
52 | wordLenghtToTake = int((wordLenght - 1) / 2) | 52 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
53 | else: | 53 | else: | ||
54 | wordLenghtToTake = int((wordLenght - 2) / 2) | 54 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
55 | 55 | ||||
56 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 56 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
57 | 57 | ||||
58 | def split_sentence(sentece): | 58 | def split_sentence(sentece): | ||
59 | splitedSentence = sentece.split(' ') | 59 | splitedSentence = sentece.split(' ') | ||
60 | result = [] | 60 | result = [] | ||
61 | for word in splitedSentence: | 61 | for word in splitedSentence: | ||
62 | beginningOfWord = beginning(word) | 62 | beginningOfWord = beginning(word) | ||
63 | middleOfWord = middle(word) | 63 | middleOfWord = middle(word) | ||
64 | endOfWord = end(word) | 64 | endOfWord = end(word) | ||
65 | result.append((beginningOfWord,middleOfWord,endOfWord)) | 65 | result.append((beginningOfWord,middleOfWord,endOfWord)) | ||
66 | 66 | ||||
t | 67 | print(result) | t | 67 | return (result) |
68 | 68 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordLenght = len(word) | 2 | wordLenght = len(word) | ||
3 | valueRemaining = wordLenght % 3 | 3 | valueRemaining = wordLenght % 3 | ||
4 | 4 | ||||
5 | if valueRemaining == 0: | 5 | if valueRemaining == 0: | ||
6 | wordLenghtToTake = int(wordLenght / 3) | 6 | wordLenghtToTake = int(wordLenght / 3) | ||
n | 7 | print(word[0:wordLenghtToTake]) | n | 7 | return (word[0:wordLenghtToTake]) |
8 | elif valueRemaining == 1: | 8 | elif valueRemaining == 1: | ||
9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
n | 10 | print(word[0:wordLenghtToTake]) | n | 10 | return (word[0:wordLenghtToTake]) |
11 | else: | 11 | else: | ||
12 | wordLenghtToTake = 0 | 12 | wordLenghtToTake = 0 | ||
13 | if (wordLenght - 1) % 2 == 0: | 13 | if (wordLenght - 1) % 2 == 0: | ||
14 | wordLenghtToTake = int((wordLenght - 1) / 2) | 14 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
15 | else: | 15 | else: | ||
16 | wordLenghtToTake = int((wordLenght - 2) / 2) | 16 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
17 | 17 | ||||
n | 18 | print(word[0:wordLenghtToTake]) | n | 18 | return (word[0:wordLenghtToTake]) |
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
21 | wordLenght = len(word) | 21 | wordLenght = len(word) | ||
22 | valueRemaining = wordLenght % 3 | 22 | valueRemaining = wordLenght % 3 | ||
23 | 23 | ||||
24 | if valueRemaining == 0: | 24 | if valueRemaining == 0: | ||
25 | wordLenghtToTake = int(wordLenght / 3) | 25 | wordLenghtToTake = int(wordLenght / 3) | ||
n | 26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | n | 26 | return (word[wordLenght - wordLenghtToTake : wordLenght]) |
27 | elif valueRemaining == 1: | 27 | elif valueRemaining == 1: | ||
28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
n | 29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | n | 29 | return (word[wordLenght - wordLenghtToTake : wordLenght]) |
30 | else: | 30 | else: | ||
31 | wordLenghtToTake = 0 | 31 | wordLenghtToTake = 0 | ||
32 | if (wordLenght - 1) % 2 == 0: | 32 | if (wordLenght - 1) % 2 == 0: | ||
33 | wordLenghtToTake = int((wordLenght - 1) / 2) | 33 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
34 | else: | 34 | else: | ||
35 | wordLenghtToTake = int((wordLenght - 2) / 2) | 35 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
36 | 36 | ||||
n | 37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | n | 37 | return (word[wordLenght - wordLenghtToTake : wordLenght]) |
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
40 | wordLenght = len(word) | 40 | wordLenght = len(word) | ||
41 | valueRemaining = wordLenght % 3 | 41 | valueRemaining = wordLenght % 3 | ||
42 | 42 | ||||
43 | if valueRemaining == 0: | 43 | if valueRemaining == 0: | ||
44 | wordLenghtToTake = int(wordLenght / 3) | 44 | wordLenghtToTake = int(wordLenght / 3) | ||
n | 45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | n | 45 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) |
46 | elif valueRemaining == 1: | 46 | elif valueRemaining == 1: | ||
47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
n | 48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | n | 48 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) |
49 | else: | 49 | else: | ||
50 | wordLenghtToTake = 0 | 50 | wordLenghtToTake = 0 | ||
51 | if (wordLenght - 1) % 2 == 0: | 51 | if (wordLenght - 1) % 2 == 0: | ||
52 | wordLenghtToTake = int((wordLenght - 1) / 2) | 52 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
53 | else: | 53 | else: | ||
54 | wordLenghtToTake = int((wordLenght - 2) / 2) | 54 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
55 | 55 | ||||
n | 56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | n | 56 | return (word[wordLenghtToTake : wordLenght - wordLenghtToTake]) |
57 | 57 | ||||
58 | def split_sentence(sentece): | 58 | def split_sentence(sentece): | ||
t | 59 | result = sentece.split(' ') | t | 59 | splitedSentence = sentece.split(' ') |
60 | for word in result: | 60 | result = [] | ||
61 | beginning(word) | 61 | for word in splitedSentence: | ||
62 | middle(word) | 62 | beginningOfWord = beginning(word) | ||
63 | end(word) | 63 | middleOfWord = middle(word) | ||
64 | endOfWord = end(word) | ||||
65 | result.append((beginningOfWord,middleOfWord,endOfWord)) | ||||
66 | |||||
67 | print(result) | ||||
64 | 68 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordLenght = len(word) | 2 | wordLenght = len(word) | ||
3 | valueRemaining = wordLenght % 3 | 3 | valueRemaining = wordLenght % 3 | ||
4 | 4 | ||||
5 | if valueRemaining == 0: | 5 | if valueRemaining == 0: | ||
6 | wordLenghtToTake = int(wordLenght / 3) | 6 | wordLenghtToTake = int(wordLenght / 3) | ||
7 | print(word[0:wordLenghtToTake]) | 7 | print(word[0:wordLenghtToTake]) | ||
8 | elif valueRemaining == 1: | 8 | elif valueRemaining == 1: | ||
9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
10 | print(word[0:wordLenghtToTake]) | 10 | print(word[0:wordLenghtToTake]) | ||
11 | else: | 11 | else: | ||
12 | wordLenghtToTake = 0 | 12 | wordLenghtToTake = 0 | ||
13 | if (wordLenght - 1) % 2 == 0: | 13 | if (wordLenght - 1) % 2 == 0: | ||
14 | wordLenghtToTake = int((wordLenght - 1) / 2) | 14 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
15 | else: | 15 | else: | ||
16 | wordLenghtToTake = int((wordLenght - 2) / 2) | 16 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
17 | 17 | ||||
18 | print(word[0:wordLenghtToTake]) | 18 | print(word[0:wordLenghtToTake]) | ||
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
21 | wordLenght = len(word) | 21 | wordLenght = len(word) | ||
22 | valueRemaining = wordLenght % 3 | 22 | valueRemaining = wordLenght % 3 | ||
23 | 23 | ||||
24 | if valueRemaining == 0: | 24 | if valueRemaining == 0: | ||
25 | wordLenghtToTake = int(wordLenght / 3) | 25 | wordLenghtToTake = int(wordLenght / 3) | ||
26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
27 | elif valueRemaining == 1: | 27 | elif valueRemaining == 1: | ||
28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
30 | else: | 30 | else: | ||
31 | wordLenghtToTake = 0 | 31 | wordLenghtToTake = 0 | ||
32 | if (wordLenght - 1) % 2 == 0: | 32 | if (wordLenght - 1) % 2 == 0: | ||
33 | wordLenghtToTake = int((wordLenght - 1) / 2) | 33 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
34 | else: | 34 | else: | ||
35 | wordLenghtToTake = int((wordLenght - 2) / 2) | 35 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
36 | 36 | ||||
37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
40 | wordLenght = len(word) | 40 | wordLenght = len(word) | ||
41 | valueRemaining = wordLenght % 3 | 41 | valueRemaining = wordLenght % 3 | ||
42 | 42 | ||||
43 | if valueRemaining == 0: | 43 | if valueRemaining == 0: | ||
44 | wordLenghtToTake = int(wordLenght / 3) | 44 | wordLenghtToTake = int(wordLenght / 3) | ||
45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
46 | elif valueRemaining == 1: | 46 | elif valueRemaining == 1: | ||
47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
49 | else: | 49 | else: | ||
50 | wordLenghtToTake = 0 | 50 | wordLenghtToTake = 0 | ||
51 | if (wordLenght - 1) % 2 == 0: | 51 | if (wordLenght - 1) % 2 == 0: | ||
52 | wordLenghtToTake = int((wordLenght - 1) / 2) | 52 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
53 | else: | 53 | else: | ||
54 | wordLenghtToTake = int((wordLenght - 2) / 2) | 54 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
55 | 55 | ||||
56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
57 | 57 | ||||
t | 58 | def split_sentence(split_sentence): | t | 58 | def split_sentence(sentece): |
59 | print() | 59 | result = sentece.split(' ') | ||
60 | for word in result: | ||||
61 | beginning(word) | ||||
62 | middle(word) | ||||
63 | end(word) | ||||
64 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordLenght = len(word) | 2 | wordLenght = len(word) | ||
3 | valueRemaining = wordLenght % 3 | 3 | valueRemaining = wordLenght % 3 | ||
4 | 4 | ||||
5 | if valueRemaining == 0: | 5 | if valueRemaining == 0: | ||
6 | wordLenghtToTake = int(wordLenght / 3) | 6 | wordLenghtToTake = int(wordLenght / 3) | ||
7 | print(word[0:wordLenghtToTake]) | 7 | print(word[0:wordLenghtToTake]) | ||
8 | elif valueRemaining == 1: | 8 | elif valueRemaining == 1: | ||
9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
10 | print(word[0:wordLenghtToTake]) | 10 | print(word[0:wordLenghtToTake]) | ||
11 | else: | 11 | else: | ||
12 | wordLenghtToTake = 0 | 12 | wordLenghtToTake = 0 | ||
13 | if (wordLenght - 1) % 2 == 0: | 13 | if (wordLenght - 1) % 2 == 0: | ||
14 | wordLenghtToTake = int((wordLenght - 1) / 2) | 14 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
15 | else: | 15 | else: | ||
16 | wordLenghtToTake = int((wordLenght - 2) / 2) | 16 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
17 | 17 | ||||
18 | print(word[0:wordLenghtToTake]) | 18 | print(word[0:wordLenghtToTake]) | ||
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
21 | wordLenght = len(word) | 21 | wordLenght = len(word) | ||
22 | valueRemaining = wordLenght % 3 | 22 | valueRemaining = wordLenght % 3 | ||
23 | 23 | ||||
24 | if valueRemaining == 0: | 24 | if valueRemaining == 0: | ||
25 | wordLenghtToTake = int(wordLenght / 3) | 25 | wordLenghtToTake = int(wordLenght / 3) | ||
26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
27 | elif valueRemaining == 1: | 27 | elif valueRemaining == 1: | ||
28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
30 | else: | 30 | else: | ||
31 | wordLenghtToTake = 0 | 31 | wordLenghtToTake = 0 | ||
32 | if (wordLenght - 1) % 2 == 0: | 32 | if (wordLenght - 1) % 2 == 0: | ||
33 | wordLenghtToTake = int((wordLenght - 1) / 2) | 33 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
34 | else: | 34 | else: | ||
35 | wordLenghtToTake = int((wordLenght - 2) / 2) | 35 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
36 | 36 | ||||
37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
40 | wordLenght = len(word) | 40 | wordLenght = len(word) | ||
41 | valueRemaining = wordLenght % 3 | 41 | valueRemaining = wordLenght % 3 | ||
42 | 42 | ||||
43 | if valueRemaining == 0: | 43 | if valueRemaining == 0: | ||
44 | wordLenghtToTake = int(wordLenght / 3) | 44 | wordLenghtToTake = int(wordLenght / 3) | ||
45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
46 | elif valueRemaining == 1: | 46 | elif valueRemaining == 1: | ||
47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
49 | else: | 49 | else: | ||
50 | wordLenghtToTake = 0 | 50 | wordLenghtToTake = 0 | ||
51 | if (wordLenght - 1) % 2 == 0: | 51 | if (wordLenght - 1) % 2 == 0: | ||
52 | wordLenghtToTake = int((wordLenght - 1) / 2) | 52 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
53 | else: | 53 | else: | ||
54 | wordLenghtToTake = int((wordLenght - 2) / 2) | 54 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
55 | 55 | ||||
56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
57 | 57 | ||||
t | t | 58 | def split_sentence(split_sentence): | ||
59 | print() |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | wordLenght = len(word) | 2 | wordLenght = len(word) | ||
3 | valueRemaining = wordLenght % 3 | 3 | valueRemaining = wordLenght % 3 | ||
4 | 4 | ||||
5 | if valueRemaining == 0: | 5 | if valueRemaining == 0: | ||
6 | wordLenghtToTake = int(wordLenght / 3) | 6 | wordLenghtToTake = int(wordLenght / 3) | ||
7 | print(word[0:wordLenghtToTake]) | 7 | print(word[0:wordLenghtToTake]) | ||
8 | elif valueRemaining == 1: | 8 | elif valueRemaining == 1: | ||
9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 9 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
10 | print(word[0:wordLenghtToTake]) | 10 | print(word[0:wordLenghtToTake]) | ||
11 | else: | 11 | else: | ||
12 | wordLenghtToTake = 0 | 12 | wordLenghtToTake = 0 | ||
13 | if (wordLenght - 1) % 2 == 0: | 13 | if (wordLenght - 1) % 2 == 0: | ||
14 | wordLenghtToTake = int((wordLenght - 1) / 2) | 14 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
15 | else: | 15 | else: | ||
16 | wordLenghtToTake = int((wordLenght - 2) / 2) | 16 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
17 | 17 | ||||
18 | print(word[0:wordLenghtToTake]) | 18 | print(word[0:wordLenghtToTake]) | ||
19 | 19 | ||||
20 | def end(word): | 20 | def end(word): | ||
21 | wordLenght = len(word) | 21 | wordLenght = len(word) | ||
22 | valueRemaining = wordLenght % 3 | 22 | valueRemaining = wordLenght % 3 | ||
23 | 23 | ||||
24 | if valueRemaining == 0: | 24 | if valueRemaining == 0: | ||
25 | wordLenghtToTake = int(wordLenght / 3) | 25 | wordLenghtToTake = int(wordLenght / 3) | ||
26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 26 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
27 | elif valueRemaining == 1: | 27 | elif valueRemaining == 1: | ||
28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 28 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 29 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
30 | else: | 30 | else: | ||
31 | wordLenghtToTake = 0 | 31 | wordLenghtToTake = 0 | ||
32 | if (wordLenght - 1) % 2 == 0: | 32 | if (wordLenght - 1) % 2 == 0: | ||
33 | wordLenghtToTake = int((wordLenght - 1) / 2) | 33 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
34 | else: | 34 | else: | ||
35 | wordLenghtToTake = int((wordLenght - 2) / 2) | 35 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
36 | 36 | ||||
37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | 37 | print(word[wordLenght - wordLenghtToTake : wordLenght]) | ||
38 | 38 | ||||
39 | def middle(word): | 39 | def middle(word): | ||
40 | wordLenght = len(word) | 40 | wordLenght = len(word) | ||
41 | valueRemaining = wordLenght % 3 | 41 | valueRemaining = wordLenght % 3 | ||
42 | 42 | ||||
43 | if valueRemaining == 0: | 43 | if valueRemaining == 0: | ||
44 | wordLenghtToTake = int(wordLenght / 3) | 44 | wordLenghtToTake = int(wordLenght / 3) | ||
45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 45 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
46 | elif valueRemaining == 1: | 46 | elif valueRemaining == 1: | ||
47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | 47 | wordLenghtToTake = int(((wordLenght)-1) / 3) | ||
48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 48 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
49 | else: | 49 | else: | ||
50 | wordLenghtToTake = 0 | 50 | wordLenghtToTake = 0 | ||
51 | if (wordLenght - 1) % 2 == 0: | 51 | if (wordLenght - 1) % 2 == 0: | ||
52 | wordLenghtToTake = int((wordLenght - 1) / 2) | 52 | wordLenghtToTake = int((wordLenght - 1) / 2) | ||
53 | else: | 53 | else: | ||
54 | wordLenghtToTake = int((wordLenght - 2) / 2) | 54 | wordLenghtToTake = int((wordLenght - 2) / 2) | ||
55 | 55 | ||||
56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | 56 | print(word[wordLenghtToTake : wordLenght - wordLenghtToTake]) | ||
57 | 57 | ||||
t | 58 | testSequence = ['шах', 'враца', 'барабани','цици','домашни'] | t | ||
59 | |||||
60 | for word in testSequence: | ||||
61 | beginning(word) | ||||
62 | middle(word) | ||||
63 | end(word) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|