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

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

10 точки общо

12 успешни теста
0 неуспешни теста
Код
Скрий всички коментари

 1DIVISIBLE = 3
 2
 3
 4def excess(word):
 5    return len(word) % DIVISIBLE
 6
 7
 8def divided_len(word):
 9    return len(word) // DIVISIBLE
10
11
12def beginning(word):
13    if excess(word) == 0 or excess(word) == 1:
14        return word[:divided_len(word)]
15    else:
16        return word[:divided_len(word) + 1]
17
18
19def middle(word):
20    if excess(word) == 0 or excess(word) == 1:
21        return word[divided_len(word):len(word) - divided_len(word)]
22    else:
23        return word[divided_len(word) + 1:len(word) - divided_len(word) - 1]
24
25
26def end(word):
27    if excess(word) == 0 or excess(word) == 1:
28        return word[len(word) - divided_len(word):]
29    else:
30        return word[len(word) - divided_len(word) - 1:]
31
32
33def split_sentence(sentence):
34    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]

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

OK

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

f1DIVISIBLE = 3f1DIVISIBLE = 3
22
33
4def excess(word):4def excess(word):
5    return len(word) % DIVISIBLE5    return len(word) % DIVISIBLE
66
77
8def divided_len(word):8def divided_len(word):
9    return len(word) // DIVISIBLE9    return len(word) // DIVISIBLE
1010
1111
12def beginning(word):12def beginning(word):
13    if excess(word) == 0 or excess(word) == 1:13    if excess(word) == 0 or excess(word) == 1:
14        return word[:divided_len(word)]14        return word[:divided_len(word)]
15    else:15    else:
16        return word[:divided_len(word) + 1]16        return word[:divided_len(word) + 1]
1717
1818
19def middle(word):19def middle(word):
20    if excess(word) == 0 or excess(word) == 1:20    if excess(word) == 0 or excess(word) == 1:
21        return word[divided_len(word):len(word) - divided_len(word)]21        return word[divided_len(word):len(word) - divided_len(word)]
22    else:22    else:
23        return word[divided_len(word) + 1:len(word) - divided_len(word) - 1]23        return word[divided_len(word) + 1:len(word) - divided_len(word) - 1]
2424
2525
26def end(word):26def end(word):
t27 t
28    if excess(word) == 0 or excess(word) == 1:27    if excess(word) == 0 or excess(word) == 1:
29        return word[len(word) - divided_len(word):]28        return word[len(word) - divided_len(word):]
30    else:29    else:
31        return word[len(word) - divided_len(word) - 1:]30        return word[len(word) - divided_len(word) - 1:]
3231
3332
34def split_sentence(sentence):33def split_sentence(sentence):
35    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]34    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]
3635
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1DIVISIBLE = 3f1DIVISIBLE = 3
22
33
4def excess(word):4def excess(word):
5    return len(word) % DIVISIBLE5    return len(word) % DIVISIBLE
66
77
8def divided_len(word):8def divided_len(word):
9    return len(word) // DIVISIBLE9    return len(word) // DIVISIBLE
1010
1111
n12def split_word(word, slicing_for_zero, slicing_for_one, slicing_for_two):n12def beginning(word):
13    if excess(word) == 0:13    if excess(word) == 0 or excess(word) == 1:
14        return slicing_for_zero14        return word[:divided_len(word)]
15    elif excess(word) == 1:
16        return slicing_for_one
17    else:15    else:
n18        return slicing_for_twon16        return word[:divided_len(word) + 1]
19 
20 
21def beginning(word):
22    return split_word(word, word[:divided_len(word)], word[:divided_len(word)], word[:divided_len(word) + 1])
2317
2418
25def middle(word):19def middle(word):
n26    return split_word(word, word[divided_len(word):len(word) - divided_len(word)],n20    if excess(word) == 0 or excess(word) == 1:
27                      word[divided_len(word):len(word) - divided_len(word)],21        return word[divided_len(word):len(word) - divided_len(word)]
22    else:
28                      word[divided_len(word) + 1:len(word) - divided_len(word) - 1])23        return word[divided_len(word) + 1:len(word) - divided_len(word) - 1]
2924
3025
31def end(word):26def end(word):
n32    return split_word(word, word[len(word) - divided_len(word):], word[len(word) - divided_len(word):],n27 
28    if excess(word) == 0 or excess(word) == 1:
29        return word[len(word) - divided_len(word):]
30    else:
33                      word[len(word) - divided_len(word) - 1:])31        return word[len(word) - divided_len(word) - 1:]
3432
3533
36def split_sentence(sentence):34def split_sentence(sentence):
37    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]35    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]
tt36 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1DIVISIBLE = 3f1DIVISIBLE = 3
22
33
4def excess(word):4def excess(word):
5    return len(word) % DIVISIBLE5    return len(word) % DIVISIBLE
66
77
8def divided_len(word):8def divided_len(word):
t9    return len(word) // 3t9    return len(word) // DIVISIBLE
1010
1111
12def split_word(word, slicing_for_zero, slicing_for_one, slicing_for_two):12def split_word(word, slicing_for_zero, slicing_for_one, slicing_for_two):
13    if excess(word) == 0:13    if excess(word) == 0:
14        return slicing_for_zero14        return slicing_for_zero
15    elif excess(word) == 1:15    elif excess(word) == 1:
16        return slicing_for_one16        return slicing_for_one
17    else:17    else:
18        return slicing_for_two18        return slicing_for_two
1919
2020
21def beginning(word):21def beginning(word):
22    return split_word(word, word[:divided_len(word)], word[:divided_len(word)], word[:divided_len(word) + 1])22    return split_word(word, word[:divided_len(word)], word[:divided_len(word)], word[:divided_len(word) + 1])
2323
2424
25def middle(word):25def middle(word):
26    return split_word(word, word[divided_len(word):len(word) - divided_len(word)],26    return split_word(word, word[divided_len(word):len(word) - divided_len(word)],
27                      word[divided_len(word):len(word) - divided_len(word)],27                      word[divided_len(word):len(word) - divided_len(word)],
28                      word[divided_len(word) + 1:len(word) - divided_len(word) - 1])28                      word[divided_len(word) + 1:len(word) - divided_len(word) - 1])
2929
3030
31def end(word):31def end(word):
32    return split_word(word, word[len(word) - divided_len(word):], word[len(word) - divided_len(word):],32    return split_word(word, word[len(word) - divided_len(word):], word[len(word) - divided_len(word):],
33                      word[len(word) - divided_len(word) - 1:])33                      word[len(word) - divided_len(word) - 1:])
3434
3535
36def split_sentence(sentence):36def split_sentence(sentence):
37    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]37    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op