f | def get_word_size(word): | f | def get_word_size(word): |
| try: | | try: |
| word_length = len(word) | | word_length = len(word) |
| return word_length | | return word_length |
| except TypeError: | | except TypeError: |
n | return False | n | return |
| | | |
| | | |
| def beginning(word): | | def beginning(word): |
| word_length = get_word_size(word) | | word_length = get_word_size(word) |
| if word_length: | | if word_length: |
| split = int(word_length / 3) | | split = int(word_length / 3) |
n | if word_length % 3 == 0: | n | if word_length % 3 == 0 or word_length % 3 == 1: |
| return word[0:split] | | |
| elif word_length % 3 == 1: | | |
| return word[0:split] | | return word[0:split] |
| else: | | else: |
| return word[0:split+1] | | return word[0:split+1] |
n | else: | n | |
| return "Invalid" | | |
| | | |
| | | |
| def middle(word): | | def middle(word): |
| word_length = get_word_size(word) | | word_length = get_word_size(word) |
| if word_length: | | if word_length: |
| split = int(word_length / 3) | | split = int(word_length / 3) |
| if word_length % 3 == 0: | | if word_length % 3 == 0: |
| return word[split:split*2] | | return word[split:split*2] |
| elif word_length % 3 == 1: | | elif word_length % 3 == 1: |
| return word[split:split*2+1] | | return word[split:split*2+1] |
| else: | | else: |
| return word[split+1:split*2+1] | | return word[split+1:split*2+1] |
n | else: | n | |
| return "Invalid" | | |
| | | |
| | | |
| def end(word): | | def end(word): |
| word_length = get_word_size(word) | | word_length = get_word_size(word) |
| if word_length: | | if word_length: |
| split = int(word_length / 3) | | split = int(word_length / 3) |
| if word_length % 3 == 0: | | if word_length % 3 == 0: |
| return word[split*2:] | | return word[split*2:] |
n | elif word_length % 3 == 1: | n | |
| return word[split*2+1:] | | |
| else: | | else: |
| return word[split*2+1:] | | return word[split*2+1:] |
n | else: | n | |
| return "Invalid" | | |
| | | |
| | | |
| def split_sentence(sentence): | | def split_sentence(sentence): |
| list_sentence = [] | | list_sentence = [] |
| sentence = sentence.split() | | sentence = sentence.split() |
n | print(sentence) | n | |
| for i in sentence: | | for i in sentence: |
n | print(i) | n | |
| list_sentence.append((beginning(i), middle(i), end(i))) | | list_sentence.append((beginning(i), middle(i), end(i))) |
| return list_sentence | | return list_sentence |
| | | |
t | | t | |
| ''' | | |
| print(beginning('шах')) | | |
| print(middle('шах')) | | |
| print(end('шах')) | | |
| print(beginning('Враца')) | | |
| print(middle('Враца')) | | |
| print(end('Враца')) | | |
| print(beginning('барабани')) | | |
| print(middle('барабани')) | | |
| print(end('барабани')) | | |
| print(beginning('цици')) | | |
| print(middle('цици')) | | |
| print(end('цици')) | | |
| print(beginning('домашни')) | | |
| print(middle('домашни')) | | |
| print(end('домашни')) | | |
| print(split_sentence('Kазвам се Джон Сноу')) | | |
| ''' | | |
| | | |