Домашни > Man who speaks the ends of words > Решения > Решението на Магдалена Иванова

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

10 точки общо

12 успешни теста
0 неуспешни теста
Код

 1def beginning(word):
 2    if len(word) % 3 == 0 or len(word) % 3 == 1:
 3        length = int(len(word) / 3)
 4        result = word[:length]
 5    elif len(word) % 3 == 2:
 6        length = int((len(word) / 3) + 1)
 7        result = word[:length]
 8    
 9    return result
10
11def middle(word):
12    if len(word) % 3 == 0:
13        length = int(len(word) / 3)
14        result = word[length:length*2]
15    elif len(word) % 3 == 2:
16        length = int((len(word) / 3) + 1)
17        result = word[length:length*2 - 1]
18    elif len(word) % 3 == 1:
19        length = int((len(word) / 3))
20        result = word[length:length*2 + 1]
21
22    return result
23
24def end(word):
25    if len(word) % 3 == 0:
26        length = int(len(word) / 3)
27        result = word[length*2:]
28    elif len(word) % 3 == 2:
29        length = int((len(word) / 3) + 1)
30        result = word[length*2 - 1:]
31    elif len(word) % 3 == 1:
32        length = int((len(word) / 3))
33        result = word[length*2 + 1:]
34
35    return result
36
37
38def split_sentence(sentence):
39    separated = sentence.split()
40    result = []
41    for i in separated:
42        triple = (beginning(i), middle(i), end(i))
43        result.append(triple)
44    return result
45
46
47sentence = "Who are you"
48splited = split_sentence(sentence)
49print(splited)

[('W', 'h', 'o'), ('a', 'r', 'e'), ('y', 'o', 'u')]
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s

OK

Дискусия
История

f1def beginning(word):f1def beginning(word):
2    if len(word) % 3 == 0 or len(word) % 3 == 1:2    if len(word) % 3 == 0 or len(word) % 3 == 1:
3        length = int(len(word) / 3)3        length = int(len(word) / 3)
4        result = word[:length]4        result = word[:length]
5    elif len(word) % 3 == 2:5    elif len(word) % 3 == 2:
6        length = int((len(word) / 3) + 1)6        length = int((len(word) / 3) + 1)
7        result = word[:length]7        result = word[:length]
8    8    
9    return result9    return result
1010
11def middle(word):11def middle(word):
12    if len(word) % 3 == 0:12    if len(word) % 3 == 0:
13        length = int(len(word) / 3)13        length = int(len(word) / 3)
14        result = word[length:length*2]14        result = word[length:length*2]
15    elif len(word) % 3 == 2:15    elif len(word) % 3 == 2:
16        length = int((len(word) / 3) + 1)16        length = int((len(word) / 3) + 1)
17        result = word[length:length*2 - 1]17        result = word[length:length*2 - 1]
18    elif len(word) % 3 == 1:18    elif len(word) % 3 == 1:
19        length = int((len(word) / 3))19        length = int((len(word) / 3))
20        result = word[length:length*2 + 1]20        result = word[length:length*2 + 1]
2121
22    return result22    return result
2323
24def end(word):24def end(word):
25    if len(word) % 3 == 0:25    if len(word) % 3 == 0:
26        length = int(len(word) / 3)26        length = int(len(word) / 3)
27        result = word[length*2:]27        result = word[length*2:]
28    elif len(word) % 3 == 2:28    elif len(word) % 3 == 2:
29        length = int((len(word) / 3) + 1)29        length = int((len(word) / 3) + 1)
30        result = word[length*2 - 1:]30        result = word[length*2 - 1:]
31    elif len(word) % 3 == 1:31    elif len(word) % 3 == 1:
32        length = int((len(word) / 3))32        length = int((len(word) / 3))
33        result = word[length*2 + 1:]33        result = word[length*2 + 1:]
3434
35    return result35    return result
3636
3737
38def split_sentence(sentence):38def split_sentence(sentence):
39    separated = sentence.split()39    separated = sentence.split()
40    result = []40    result = []
41    for i in separated:41    for i in separated:
42        triple = (beginning(i), middle(i), end(i))42        triple = (beginning(i), middle(i), end(i))
43        result.append(triple)43        result.append(triple)
44    return result44    return result
4545
4646
t47 t47sentence = "Who are you"
48splited = split_sentence(sentence)48splited = split_sentence(sentence)
49print(splited)49print(splited)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
n2    if len(word) % 3 == 0:n2    if len(word) % 3 == 0 or len(word) % 3 == 1:
3        length = int(len(word) / 3)3        length = int(len(word) / 3)
4        result = word[:length]4        result = word[:length]
5    elif len(word) % 3 == 2:5    elif len(word) % 3 == 2:
6        length = int((len(word) / 3) + 1)6        length = int((len(word) / 3) + 1)
n7        result = word[:length]n
8    elif len(word) % 3 == 1:
9        length = int((len(word) / 3))
10        result = word[:length]7        result = word[:length]
11    8    
12    return result9    return result
1310
14def middle(word):11def middle(word):
15    if len(word) % 3 == 0:12    if len(word) % 3 == 0:
16        length = int(len(word) / 3)13        length = int(len(word) / 3)
17        result = word[length:length*2]14        result = word[length:length*2]
18    elif len(word) % 3 == 2:15    elif len(word) % 3 == 2:
19        length = int((len(word) / 3) + 1)16        length = int((len(word) / 3) + 1)
n20        result = word[length:length*2-1]n17        result = word[length:length*2 - 1]
21    elif len(word) % 3 == 1:18    elif len(word) % 3 == 1:
22        length = int((len(word) / 3))19        length = int((len(word) / 3))
n23        result = word[length:length*2+1]n20        result = word[length:length*2 + 1]
2421
25    return result22    return result
2623
27def end(word):24def end(word):
28    if len(word) % 3 == 0:25    if len(word) % 3 == 0:
29        length = int(len(word) / 3)26        length = int(len(word) / 3)
30        result = word[length*2:]27        result = word[length*2:]
31    elif len(word) % 3 == 2:28    elif len(word) % 3 == 2:
32        length = int((len(word) / 3) + 1)29        length = int((len(word) / 3) + 1)
n33        result = word[length*2-1:]n30        result = word[length*2 - 1:]
34    elif len(word) % 3 == 1:31    elif len(word) % 3 == 1:
35        length = int((len(word) / 3))32        length = int((len(word) / 3))
n36        result = word[length*2+1:]n33        result = word[length*2 + 1:]
3734
38    return result35    return result
3936
4037
41def split_sentence(sentence):38def split_sentence(sentence):
42    separated = sentence.split()39    separated = sentence.split()
n43    result=[]n40    result = []
44    for i in separated:41    for i in separated:
45        triple = (beginning(i), middle(i), end(i))42        triple = (beginning(i), middle(i), end(i))
46        result.append(triple)43        result.append(triple)
47    return result44    return result
4845
4946
5047
t51 t
52sentence = input()
53splited = split_sentence(sentence)48splited = split_sentence(sentence)
54print(splited)49print(splited)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1def beginning(word):t1def beginning(word):
2    if len(word) % 3 == 0:2    if len(word) % 3 == 0:
3        length = int(len(word) / 3)3        length = int(len(word) / 3)
4        result = word[:length]4        result = word[:length]
5    elif len(word) % 3 == 2:5    elif len(word) % 3 == 2:
6        length = int((len(word) / 3) + 1)6        length = int((len(word) / 3) + 1)
7        result = word[:length]7        result = word[:length]
8    elif len(word) % 3 == 1:8    elif len(word) % 3 == 1:
9        length = int((len(word) / 3))9        length = int((len(word) / 3))
10        result = word[:length]10        result = word[:length]
11    11    
12    return result12    return result
1313
14def middle(word):14def middle(word):
15    if len(word) % 3 == 0:15    if len(word) % 3 == 0:
16        length = int(len(word) / 3)16        length = int(len(word) / 3)
17        result = word[length:length*2]17        result = word[length:length*2]
18    elif len(word) % 3 == 2:18    elif len(word) % 3 == 2:
19        length = int((len(word) / 3) + 1)19        length = int((len(word) / 3) + 1)
20        result = word[length:length*2-1]20        result = word[length:length*2-1]
21    elif len(word) % 3 == 1:21    elif len(word) % 3 == 1:
22        length = int((len(word) / 3))22        length = int((len(word) / 3))
23        result = word[length:length*2+1]23        result = word[length:length*2+1]
2424
25    return result25    return result
2626
27def end(word):27def end(word):
28    if len(word) % 3 == 0:28    if len(word) % 3 == 0:
29        length = int(len(word) / 3)29        length = int(len(word) / 3)
30        result = word[length*2:]30        result = word[length*2:]
31    elif len(word) % 3 == 2:31    elif len(word) % 3 == 2:
32        length = int((len(word) / 3) + 1)32        length = int((len(word) / 3) + 1)
33        result = word[length*2-1:]33        result = word[length*2-1:]
34    elif len(word) % 3 == 1:34    elif len(word) % 3 == 1:
35        length = int((len(word) / 3))35        length = int((len(word) / 3))
36        result = word[length*2+1:]36        result = word[length*2+1:]
3737
38    return result38    return result
3939
4040
41def split_sentence(sentence):41def split_sentence(sentence):
42    separated = sentence.split()42    separated = sentence.split()
43    result=[]43    result=[]
44    for i in separated:44    for i in separated:
45        triple = (beginning(i), middle(i), end(i))45        triple = (beginning(i), middle(i), end(i))
46        result.append(triple)46        result.append(triple)
47    return result47    return result
4848
4949
5050
5151
52sentence = input()52sentence = input()
53splited = split_sentence(sentence)53splited = split_sentence(sentence)
54print(splited)54print(splited)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def beginning(word):f1def beginning(word):
2    if len(word) % 3 == 0:2    if len(word) % 3 == 0:
3        length = int(len(word) / 3)3        length = int(len(word) / 3)
4        result = word[:length]4        result = word[:length]
5    elif len(word) % 3 == 2:5    elif len(word) % 3 == 2:
6        length = int((len(word) / 3) + 1)6        length = int((len(word) / 3) + 1)
7        result = word[:length]7        result = word[:length]
8    elif len(word) % 3 == 1:8    elif len(word) % 3 == 1:
9        length = int((len(word) / 3))9        length = int((len(word) / 3))
10        result = word[:length]10        result = word[:length]
11    11    
12    return result12    return result
1313
14def middle(word):14def middle(word):
15    if len(word) % 3 == 0:15    if len(word) % 3 == 0:
16        length = int(len(word) / 3)16        length = int(len(word) / 3)
17        result = word[length:length*2]17        result = word[length:length*2]
18    elif len(word) % 3 == 2:18    elif len(word) % 3 == 2:
19        length = int((len(word) / 3) + 1)19        length = int((len(word) / 3) + 1)
20        result = word[length:length*2-1]20        result = word[length:length*2-1]
21    elif len(word) % 3 == 1:21    elif len(word) % 3 == 1:
22        length = int((len(word) / 3))22        length = int((len(word) / 3))
23        result = word[length:length*2+1]23        result = word[length:length*2+1]
2424
25    return result25    return result
2626
27def end(word):27def end(word):
28    if len(word) % 3 == 0:28    if len(word) % 3 == 0:
29        length = int(len(word) / 3)29        length = int(len(word) / 3)
30        result = word[length*2:]30        result = word[length*2:]
31    elif len(word) % 3 == 2:31    elif len(word) % 3 == 2:
32        length = int((len(word) / 3) + 1)32        length = int((len(word) / 3) + 1)
33        result = word[length*2-1:]33        result = word[length*2-1:]
34    elif len(word) % 3 == 1:34    elif len(word) % 3 == 1:
35        length = int((len(word) / 3))35        length = int((len(word) / 3))
36        result = word[length*2+1:]36        result = word[length*2+1:]
3737
38    return result38    return result
3939
4040
41def split_sentence(sentence):41def split_sentence(sentence):
42    separated = sentence.split()42    separated = sentence.split()
43    result=[]43    result=[]
44    for i in separated:44    for i in separated:
45        triple = (beginning(i), middle(i), end(i))45        triple = (beginning(i), middle(i), end(i))
46        result.append(triple)46        result.append(triple)
n47    print(result)n47    return result
4848
4949
5050
5151
52sentence = input()52sentence = input()
t53split_sentence(sentence)t53splited = split_sentence(sentence)
54print(splited)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op