1# Homework 1
2
3
4def beginning(word):
5 length = len(word)
6 if length % 3 == 0:
7 return word[:length // 3]
8 if length % 3 == 1:
9 return word[:length // 3]
10 if length % 3 == 2:
11 return word[:length // 3 + 1]
12
13
14def middle(word):
15 length = len(word)
16 if length % 3 == 0:
17 return word[length // 3:2 * (length // 3)]
18 if length % 3 == 1:
19 return word[length // 3:2 * (length // 3) + 1]
20 if length % 3 == 2:
21 return word[length // 3 + 1:2 * (length // 3) + 1]
22
23
24def end(word):
25 length = len(word)
26 if length % 3 == 0:
27 return word[2 * (length // 3):]
28 if length % 3 == 1:
29 return word[2 * (length // 3) + 1:]
30 if length % 3 == 2:
31 return word[2 * (length // 3) + 1:]
32
33
34def split_sentence(sentence):
35 words = sentence.split()
36 result = [(beginning(word), middle(word), end(word)) for word in words]
37 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Микаела Езекиева
11.10.2023 20:15Съгласна! Излишен ред продуцирам така :)
|
f | 1 | # Homework 1 | f | 1 | # Homework 1 |
2 | 2 | ||||
3 | 3 | ||||
4 | def beginning(word): | 4 | def beginning(word): | ||
5 | length = len(word) | 5 | length = len(word) | ||
6 | if length % 3 == 0: | 6 | if length % 3 == 0: | ||
7 | return word[:length // 3] | 7 | return word[:length // 3] | ||
8 | if length % 3 == 1: | 8 | if length % 3 == 1: | ||
9 | return word[:length // 3] | 9 | return word[:length // 3] | ||
10 | if length % 3 == 2: | 10 | if length % 3 == 2: | ||
11 | return word[:length // 3 + 1] | 11 | return word[:length // 3 + 1] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word): | 14 | def middle(word): | ||
15 | length = len(word) | 15 | length = len(word) | ||
16 | if length % 3 == 0: | 16 | if length % 3 == 0: | ||
17 | return word[length // 3:2 * (length // 3)] | 17 | return word[length // 3:2 * (length // 3)] | ||
18 | if length % 3 == 1: | 18 | if length % 3 == 1: | ||
19 | return word[length // 3:2 * (length // 3) + 1] | 19 | return word[length // 3:2 * (length // 3) + 1] | ||
20 | if length % 3 == 2: | 20 | if length % 3 == 2: | ||
21 | return word[length // 3 + 1:2 * (length // 3) + 1] | 21 | return word[length // 3 + 1:2 * (length // 3) + 1] | ||
22 | 22 | ||||
23 | 23 | ||||
24 | def end(word): | 24 | def end(word): | ||
25 | length = len(word) | 25 | length = len(word) | ||
26 | if length % 3 == 0: | 26 | if length % 3 == 0: | ||
27 | return word[2 * (length // 3):] | 27 | return word[2 * (length // 3):] | ||
28 | if length % 3 == 1: | 28 | if length % 3 == 1: | ||
29 | return word[2 * (length // 3) + 1:] | 29 | return word[2 * (length // 3) + 1:] | ||
30 | if length % 3 == 2: | 30 | if length % 3 == 2: | ||
31 | return word[2 * (length // 3) + 1:] | 31 | return word[2 * (length // 3) + 1:] | ||
32 | 32 | ||||
33 | 33 | ||||
34 | def split_sentence(sentence): | 34 | def split_sentence(sentence): | ||
35 | words = sentence.split() | 35 | words = sentence.split() | ||
t | 36 | list = [(beginning(word), middle(word), end(word)) for word in words] | t | 36 | result = [(beginning(word), middle(word), end(word)) for word in words] |
37 | return list | 37 | return result |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | # Homework 1 | f | 1 | # Homework 1 |
2 | 2 | ||||
3 | 3 | ||||
4 | def beginning(word): | 4 | def beginning(word): | ||
5 | length = len(word) | 5 | length = len(word) | ||
6 | if length % 3 == 0: | 6 | if length % 3 == 0: | ||
7 | return word[:length // 3] | 7 | return word[:length // 3] | ||
8 | if length % 3 == 1: | 8 | if length % 3 == 1: | ||
9 | return word[:length // 3] | 9 | return word[:length // 3] | ||
10 | if length % 3 == 2: | 10 | if length % 3 == 2: | ||
11 | return word[:length // 3 + 1] | 11 | return word[:length // 3 + 1] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word): | 14 | def middle(word): | ||
15 | length = len(word) | 15 | length = len(word) | ||
16 | if length % 3 == 0: | 16 | if length % 3 == 0: | ||
17 | return word[length // 3:2 * (length // 3)] | 17 | return word[length // 3:2 * (length // 3)] | ||
18 | if length % 3 == 1: | 18 | if length % 3 == 1: | ||
19 | return word[length // 3:2 * (length // 3) + 1] | 19 | return word[length // 3:2 * (length // 3) + 1] | ||
20 | if length % 3 == 2: | 20 | if length % 3 == 2: | ||
21 | return word[length // 3 + 1:2 * (length // 3) + 1] | 21 | return word[length // 3 + 1:2 * (length // 3) + 1] | ||
22 | 22 | ||||
23 | 23 | ||||
24 | def end(word): | 24 | def end(word): | ||
25 | length = len(word) | 25 | length = len(word) | ||
26 | if length % 3 == 0: | 26 | if length % 3 == 0: | ||
27 | return word[2 * (length // 3):] | 27 | return word[2 * (length // 3):] | ||
28 | if length % 3 == 1: | 28 | if length % 3 == 1: | ||
29 | return word[2 * (length // 3) + 1:] | 29 | return word[2 * (length // 3) + 1:] | ||
30 | if length % 3 == 2: | 30 | if length % 3 == 2: | ||
31 | return word[2 * (length // 3) + 1:] | 31 | return word[2 * (length // 3) + 1:] | ||
32 | 32 | ||||
33 | 33 | ||||
34 | def split_sentence(sentence): | 34 | def split_sentence(sentence): | ||
35 | words = sentence.split() | 35 | words = sentence.split() | ||
n | 36 | list = '"[' + ', '.join(f"('{beginning(word)}', '{middle(word)}', '{end(word)}')" for word in words) + ']"' | n | 36 | list = [(beginning(word), middle(word), end(word)) for word in words] |
37 | return list | 37 | return list | ||
t | 38 | t |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | # Homework 1 | f | 1 | # Homework 1 |
2 | 2 | ||||
3 | 3 | ||||
4 | def beginning(word): | 4 | def beginning(word): | ||
5 | length = len(word) | 5 | length = len(word) | ||
6 | if length % 3 == 0: | 6 | if length % 3 == 0: | ||
7 | return word[:length // 3] | 7 | return word[:length // 3] | ||
8 | if length % 3 == 1: | 8 | if length % 3 == 1: | ||
9 | return word[:length // 3] | 9 | return word[:length // 3] | ||
10 | if length % 3 == 2: | 10 | if length % 3 == 2: | ||
11 | return word[:length // 3 + 1] | 11 | return word[:length // 3 + 1] | ||
12 | 12 | ||||
13 | 13 | ||||
14 | def middle(word): | 14 | def middle(word): | ||
15 | length = len(word) | 15 | length = len(word) | ||
16 | if length % 3 == 0: | 16 | if length % 3 == 0: | ||
17 | return word[length // 3:2 * (length // 3)] | 17 | return word[length // 3:2 * (length // 3)] | ||
18 | if length % 3 == 1: | 18 | if length % 3 == 1: | ||
19 | return word[length // 3:2 * (length // 3) + 1] | 19 | return word[length // 3:2 * (length // 3) + 1] | ||
20 | if length % 3 == 2: | 20 | if length % 3 == 2: | ||
21 | return word[length // 3 + 1:2 * (length // 3) + 1] | 21 | return word[length // 3 + 1:2 * (length // 3) + 1] | ||
22 | 22 | ||||
23 | 23 | ||||
24 | def end(word): | 24 | def end(word): | ||
25 | length = len(word) | 25 | length = len(word) | ||
26 | if length % 3 == 0: | 26 | if length % 3 == 0: | ||
27 | return word[2 * (length // 3):] | 27 | return word[2 * (length // 3):] | ||
28 | if length % 3 == 1: | 28 | if length % 3 == 1: | ||
29 | return word[2 * (length // 3) + 1:] | 29 | return word[2 * (length // 3) + 1:] | ||
30 | if length % 3 == 2: | 30 | if length % 3 == 2: | ||
31 | return word[2 * (length // 3) + 1:] | 31 | return word[2 * (length // 3) + 1:] | ||
32 | 32 | ||||
33 | 33 | ||||
34 | def split_sentence(sentence): | 34 | def split_sentence(sentence): | ||
35 | words = sentence.split() | 35 | words = sentence.split() | ||
t | 36 | list = '[' + ', '.join(f"('{beginning(word)}', '{middle(word)}', '{end(word)}')" for word in words) + ']' | t | 36 | list = '"[' + ', '.join(f"('{beginning(word)}', '{middle(word)}', '{end(word)}')" for word in words) + ']"' |
37 | return list | 37 | return list | ||
38 | 38 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
11.10.2023 18:24