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

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

10 точки общо

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

 1def divide(word, divider=3):
 2    return len(word) // divider, len(word) % divider
 3
 4def beginning(word):
 5    whole, remainder = divide(word)
 6    return word[:whole + remainder // 2]
 7
 8def middle(word):
 9    whole, remainder = divide(word)
10    return word[whole + remainder // 2:2 * whole + (1 if remainder > 0 else 0)]
11
12def end(word):
13    whole, remainder = divide(word)
14    return word[2 * whole + (1 if remainder > 0 else 0):]
15
16def split_sentence(sentence):
17    return [(beginning(word), middle(word), end(word)) for word in sentence.split()]

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

OK

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

n1def divide(word, divider = 3):n1def divide(word, divider=3):
2    return len(word) // divider, len(word) % divider2    return len(word) // divider, len(word) % divider
n3    n3 
4def beginning(word):4def beginning(word):
5    whole, remainder = divide(word)5    whole, remainder = divide(word)
6    return word[:whole + remainder // 2]6    return word[:whole + remainder // 2]
77
8def middle(word):8def middle(word):
9    whole, remainder = divide(word)9    whole, remainder = divide(word)
10    return word[whole + remainder // 2:2 * whole + (1 if remainder > 0 else 0)]10    return word[whole + remainder // 2:2 * whole + (1 if remainder > 0 else 0)]
1111
12def end(word):12def end(word):
13    whole, remainder = divide(word)13    whole, remainder = divide(word)
14    return word[2 * whole + (1 if remainder > 0 else 0):]14    return word[2 * whole + (1 if remainder > 0 else 0):]
1515
16def split_sentence(sentence):16def split_sentence(sentence):
t17    return [(beginning(word), middle(word), end(word)) for word in sentence.split(' ')]t17    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