Домашни > Man who speaks the ends of words > Решения > Решението на Константин Кирязов

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

10 точки общо

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

 1def beginning(word):
 2    if type(word) is not str:
 3        print(f"{word} is not a word, sorry. Input a string next time.")
 4        return None
 5    slice_length = len(word) // 3
 6    residue = len(word) % 3
 7    if residue:
 8        return word[: slice_length + residue - 1]    
 9    return word[:slice_length]
10
11
12def middle(word):
13    if type(word) is not str:
14        print(f"{word} is not a word :/ input a string.")
15        return None
16    if len(word) == 1:
17        return word
18    slice_length = len(word) // 3
19    residue = len(word) % 3
20    if residue:
21        return word[slice_length + residue - 1 : -slice_length - residue + 1]
22    return word[slice_length : -slice_length]
23
24
25def end(word):
26    if type(word) is not str:
27        print(f"{word} is not a word, try inputting a string :)")
28        return None
29    slice_length = len(word) // 3
30    residue = len(word) % 3
31    if residue:
32        return word[2*slice_length + 1 :]
33    return word[-slice_length :]
34
35
36def split_sentence(sentence):
37    if type(sentence) is not str:
38        print(f"{sentence} isn't a string. Try again.")
39        return None
40    new_sentence = []
41    for word in sentence.split():
42        new_sentence.append((beginning(word),
43                             middle(word),
44                             end(word)))
45    return new_sentence

............
----------------------------------------------------------------------
Ran 12 tests in 0.000s

OK

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

f1def beginning(word):f1def beginning(word):
2    if type(word) is not str:2    if type(word) is not str:
3        print(f"{word} is not a word, sorry. Input a string next time.")3        print(f"{word} is not a word, sorry. Input a string next time.")
4        return None4        return None
n5    else:n
6        slice_length = len(word) // 35    slice_length = len(word) // 3
7        residue = len(word) % 36    residue = len(word) % 3
8        if residue:7    if residue:
9            return word[: slice_length + residue - 1]    8        return word[: slice_length + residue - 1]    
10        else:
11           return word[: slice_length]9    return word[:slice_length]
1210
1311
14def middle(word):12def middle(word):
15    if type(word) is not str:13    if type(word) is not str:
16        print(f"{word} is not a word :/ input a string.")14        print(f"{word} is not a word :/ input a string.")
17        return None15        return None
n18    else:n
19        if len(word) == 1:16    if len(word) == 1:
20            return word17        return word
21        slice_length = len(word) // 318    slice_length = len(word) // 3
22        residue = len(word) % 319    residue = len(word) % 3
23        if residue:20    if residue:
24           return word[slice_length + residue - 1 21        return word[slice_length + residue - 1 : -slice_length - residue + 1]
25                       : -slice_length - residue + 1]
26        else:
27           return word[slice_length : -slice_length]22    return word[slice_length : -slice_length]
2823
2924
30def end(word):25def end(word):
31    if type(word) is not str:26    if type(word) is not str:
32        print(f"{word} is not a word, try inputting a string :)")27        print(f"{word} is not a word, try inputting a string :)")
33        return None28        return None
n34    else:n
35        slice_length = len(word) // 329    slice_length = len(word) // 3
36        residue = len(word) % 330    residue = len(word) % 3
37        if residue:31    if residue:
38           return word[2*slice_length + 1 :]32        return word[2*slice_length + 1 :]
39        else:
40            return word[-slice_length :]33    return word[-slice_length :]
4134
4235
43def split_sentence(sentence):36def split_sentence(sentence):
44    if type(sentence) is not str:37    if type(sentence) is not str:
45        print(f"{sentence} isn't a string. Try again.")38        print(f"{sentence} isn't a string. Try again.")
46        return None39        return None
t47    else:t40    new_sentence = []
48        new_sentence = sentence.split()41    for word in sentence.split():
49        for word in range(len(new_sentence)):42        new_sentence.append((beginning(word),
50            new_sentence[word] = (43                             middle(word),
51                beginning(new_sentence[word]),44                             end(word)))
52                middle(new_sentence[word]),
53                end(new_sentence[word])
54                )
55    return new_sentence45    return new_sentence
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op