Домашни > Man who speaks the ends of words > Решения > Решението на Пламена Николова

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

10 точки общо

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

 1def beginning(word):
 2    length = len(word)
 3    if len(word) % 3 == 2:
 4        return word[:length//3+1]
 5    return word[:length//3]
 6
 7def middle(word):
 8    length = len(word)
 9    if length % 3 == 0:
10        return word[length//3:length//3*2]
11    elif length % 3 == 2:
12        return word[length//3+1:length//3*2+1]
13    return word[length//3:2*length//3+1]
14
15def end(word):
16    length = len(word)
17    if length % 3 == 0:
18        return word[2*length//3:]
19    return word[length//3*2+1:]
20    
21def split_sentence(sentence):
22    result = []
23    for word in sentence.split():
24        result.append((beginning(word), middle(word), end(word)))   
25    return result

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

OK

Дискусия
Георги Кунчев
12.10.2023 10:45

Да, сега вече всичко с табулациите е наред. Нямам други коментари по кода, които се заслужава да бъдат споделени.
Пламена Николова
12.10.2023 10:39

Добавих това в json файла на VS Code. Надявам се вече да излиза и при вас с 4 интервала. При мен не дава грешка. "[python]": { "editor.detectIndentation" : false, "editor.insertSpaces": true, "editor.tabSize": 4 } Поправих всичко друго. Благодаря за бързия отзив.
Георги Кунчев
12.10.2023 09:39

Използвай 4 интервала, а не табулация. За такава дреболия ще махаме точки.
История

n1def beginning(word): n1def beginning(word):
2    length = len(word)
2    if len(word) % 3 == 2:3    if len(word) % 3 == 2:
n3        return word[:len(word)//3+1]n4        return word[:length//3+1]
4    return word[:len(word)//3]5    return word[:length//3]
56
6def middle(word):7def middle(word):
n7        if len(word) % 3 == 0:n8    length = len(word)
8                return word[len(word)//3:len(word)//3*2]9    if length % 3 == 0:
9        elif len(word) % 3 == 2:10        return word[length//3:length//3*2]
10                return word[len(word)//3+1:len(word)//3*2+1]11    elif length % 3 == 2:
11        return word[len(word)//3:2*len(word)//3+1]12        return word[length//3+1:length//3*2+1]
13    return word[length//3:2*length//3+1]
1214
13def end(word):15def end(word):
nn16    length = len(word)
14    if len(word) % 3 == 0:17    if length % 3 == 0:
15        return word[2*len(word)//3:]18        return word[2*length//3:]
16    return word[len(word)//3*2+1:]19    return word[length//3*2+1:]
17    20    
18def split_sentence(sentence):21def split_sentence(sentence):
t19        result = []t22    result = []
20        words = sentence.split()23    for word in sentence.split():
21        for word in words:
22                result.append((beginning(word), middle(word), end(word)))24        result.append((beginning(word), middle(word), end(word)))   
23        return result25    return result
24print(split_sentence("Kазвам се Джон Сноу"))26 
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 == 2:2    if len(word) % 3 == 2:
3        return word[:len(word)//3+1]3        return word[:len(word)//3+1]
4    return word[:len(word)//3]4    return word[:len(word)//3]
55
6def middle(word):6def middle(word):
7        if len(word) % 3 == 0:7        if len(word) % 3 == 0:
8                return word[len(word)//3:len(word)//3*2]8                return word[len(word)//3:len(word)//3*2]
9        elif len(word) % 3 == 2:9        elif len(word) % 3 == 2:
10                return word[len(word)//3+1:len(word)//3*2+1]10                return word[len(word)//3+1:len(word)//3*2+1]
11        return word[len(word)//3:2*len(word)//3+1]11        return word[len(word)//3:2*len(word)//3+1]
1212
13def end(word):13def end(word):
14    if len(word) % 3 == 0:14    if len(word) % 3 == 0:
15        return word[2*len(word)//3:]15        return word[2*len(word)//3:]
16    return word[len(word)//3*2+1:]16    return word[len(word)//3*2+1:]
17    17    
tt18def split_sentence(sentence):
19        result = []
20        words = sentence.split()
21        for word in words:
22                result.append((beginning(word), middle(word), end(word)))
23        return result
24print(split_sentence("Kазвам се Джон Сноу"))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op