1'''Homework 1'''
2
3
4def beginning(word: str):
5 '''Returns first third of word'''
6 length = len(word)
7 if length % 3 == 0:
8 return word[:length // 3]
9 if length % 3 == 2:
10 return word[:length // 3 + 1]
11 return word[:length // 3]
12
13
14def middle(word: str):
15 '''Returns second third of word'''
16 length = len(word)
17 if length % 3 == 0:
18 return word[length // 3:length // 3 * 2]
19 if length % 3 == 2:
20 return word[length // 3 + 1:length // 3 * 2 + 1]
21 return word[length // 3:length // 3 * 2 + 1]
22
23
24def end(word: str):
25 '''Returns third third of word'''
26 length = len(word)
27 if length % 3 == 0:
28 return word[2 * length // 3:]
29 if length % 3 == 2:
30 return word[2 * length // 3:]
31 return word[2 * length // 3 + 1:]
32
33
34def split_sentence(sentence : str):
35 '''Returns all of the words split by spaces in tuples of
36 beggining, middle and end parts'''
37 results = []
38 for word in sentence.split():
39 results.append((beginning(word), middle(word), end(word)))
40 return results
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
f | 1 | '''Homework 1''' | f | 1 | '''Homework 1''' |
2 | 2 | ||||
3 | 3 | ||||
4 | def beginning(word: str): | 4 | def beginning(word: str): | ||
5 | '''Returns first third of word''' | 5 | '''Returns first third of word''' | ||
6 | length = len(word) | 6 | length = len(word) | ||
7 | if length % 3 == 0: | 7 | if length % 3 == 0: | ||
8 | return word[:length // 3] | 8 | return word[:length // 3] | ||
9 | if length % 3 == 2: | 9 | if length % 3 == 2: | ||
10 | return word[:length // 3 + 1] | 10 | return word[:length // 3 + 1] | ||
11 | return word[:length // 3] | 11 | return word[:length // 3] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word: str): | 14 | def middle(word: str): | ||
15 | '''Returns second third of word''' | 15 | '''Returns second third of word''' | ||
16 | length = len(word) | 16 | length = len(word) | ||
17 | if length % 3 == 0: | 17 | if length % 3 == 0: | ||
18 | return word[length // 3:length // 3 * 2] | 18 | return word[length // 3:length // 3 * 2] | ||
19 | if length % 3 == 2: | 19 | if length % 3 == 2: | ||
20 | return word[length // 3 + 1:length // 3 * 2 + 1] | 20 | return word[length // 3 + 1:length // 3 * 2 + 1] | ||
21 | return word[length // 3:length // 3 * 2 + 1] | 21 | return word[length // 3:length // 3 * 2 + 1] | ||
22 | 22 | ||||
23 | 23 | ||||
24 | def end(word: str): | 24 | def end(word: str): | ||
25 | '''Returns third third of word''' | 25 | '''Returns third third of word''' | ||
26 | length = len(word) | 26 | length = len(word) | ||
27 | if length % 3 == 0: | 27 | if length % 3 == 0: | ||
28 | return word[2 * length // 3:] | 28 | return word[2 * length // 3:] | ||
29 | if length % 3 == 2: | 29 | if length % 3 == 2: | ||
30 | return word[2 * length // 3:] | 30 | return word[2 * length // 3:] | ||
31 | return word[2 * length // 3 + 1:] | 31 | return word[2 * length // 3 + 1:] | ||
32 | 32 | ||||
33 | 33 | ||||
34 | def split_sentence(sentence : str): | 34 | def split_sentence(sentence : str): | ||
35 | '''Returns all of the words split by spaces in tuples of | 35 | '''Returns all of the words split by spaces in tuples of | ||
36 | beggining, middle and end parts''' | 36 | beggining, middle and end parts''' | ||
37 | results = [] | 37 | results = [] | ||
t | 38 | for word in sentence.split(" "): | t | 38 | for word in sentence.split(): |
39 | results.append((beginning(word), middle(word), end(word))) | 39 | results.append((beginning(word), middle(word), end(word))) | ||
40 | return results | 40 | return results |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | '''Homework 1''' | t | 1 | '''Homework 1''' |
2 | 2 | ||||
3 | 3 | ||||
4 | def beginning(word: str): | 4 | def beginning(word: str): | ||
5 | '''Returns first third of word''' | 5 | '''Returns first third of word''' | ||
6 | length = len(word) | 6 | length = len(word) | ||
7 | if length % 3 == 0: | 7 | if length % 3 == 0: | ||
8 | return word[:length // 3] | 8 | return word[:length // 3] | ||
9 | if length % 3 == 2: | 9 | if length % 3 == 2: | ||
10 | return word[:length // 3 + 1] | 10 | return word[:length // 3 + 1] | ||
11 | return word[:length // 3] | 11 | return word[:length // 3] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word: str): | 14 | def middle(word: str): | ||
15 | '''Returns second third of word''' | 15 | '''Returns second third of word''' | ||
16 | length = len(word) | 16 | length = len(word) | ||
17 | if length % 3 == 0: | 17 | if length % 3 == 0: | ||
18 | return word[length // 3:length // 3 * 2] | 18 | return word[length // 3:length // 3 * 2] | ||
19 | if length % 3 == 2: | 19 | if length % 3 == 2: | ||
20 | return word[length // 3 + 1:length // 3 * 2 + 1] | 20 | return word[length // 3 + 1:length // 3 * 2 + 1] | ||
21 | return word[length // 3:length // 3 * 2 + 1] | 21 | return word[length // 3:length // 3 * 2 + 1] | ||
22 | 22 | ||||
23 | 23 | ||||
24 | def end(word: str): | 24 | def end(word: str): | ||
25 | '''Returns third third of word''' | 25 | '''Returns third third of word''' | ||
26 | length = len(word) | 26 | length = len(word) | ||
27 | if length % 3 == 0: | 27 | if length % 3 == 0: | ||
28 | return word[2 * length // 3:] | 28 | return word[2 * length // 3:] | ||
29 | if length % 3 == 2: | 29 | if length % 3 == 2: | ||
30 | return word[2 * length // 3:] | 30 | return word[2 * length // 3:] | ||
31 | return word[2 * length // 3 + 1:] | 31 | return word[2 * length // 3 + 1:] | ||
32 | 32 | ||||
33 | 33 | ||||
34 | def split_sentence(sentence : str): | 34 | def split_sentence(sentence : str): | ||
35 | '''Returns all of the words split by spaces in tuples of | 35 | '''Returns all of the words split by spaces in tuples of | ||
36 | beggining, middle and end parts''' | 36 | beggining, middle and end parts''' | ||
37 | results = [] | 37 | results = [] | ||
38 | for word in sentence.split(" "): | 38 | for word in sentence.split(" "): | ||
39 | results.append((beginning(word), middle(word), end(word))) | 39 | results.append((beginning(word), middle(word), end(word))) | ||
40 | return results | 40 | return results |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
16.10.2023 09:14