f | def beginning(word): | f | def beginning(word): |
| if type(word) is not str: | | if type(word) is not str: |
| print(f"{word} is not a word, sorry. Input a string next time.") | | print(f"{word} is not a word, sorry. Input a string next time.") |
| return None | | return None |
n | else: | n | |
| slice_length = len(word) // 3 | | slice_length = len(word) // 3 |
| residue = len(word) % 3 | | residue = len(word) % 3 |
| if residue: | | if residue: |
| return word[: slice_length + residue - 1] | | return word[: slice_length + residue - 1] |
| else: | | |
| return word[: slice_length] | | return word[:slice_length] |
| | | |
| | | |
| def middle(word): | | def middle(word): |
| if type(word) is not str: | | if type(word) is not str: |
| print(f"{word} is not a word :/ input a string.") | | print(f"{word} is not a word :/ input a string.") |
| return None | | return None |
n | else: | n | |
| if len(word) == 1: | | if len(word) == 1: |
| return word | | return word |
| slice_length = len(word) // 3 | | slice_length = len(word) // 3 |
| residue = len(word) % 3 | | residue = len(word) % 3 |
| if residue: | | if residue: |
| return word[slice_length + residue - 1 | | return word[slice_length + residue - 1 : -slice_length - residue + 1] |
| : -slice_length - residue + 1] | | |
| else: | | |
| return word[slice_length : -slice_length] | | return word[slice_length : -slice_length] |
| | | |
| | | |
| def end(word): | | def end(word): |
| if type(word) is not str: | | if type(word) is not str: |
| print(f"{word} is not a word, try inputting a string :)") | | print(f"{word} is not a word, try inputting a string :)") |
| return None | | return None |
n | else: | n | |
| slice_length = len(word) // 3 | | slice_length = len(word) // 3 |
| residue = len(word) % 3 | | residue = len(word) % 3 |
| if residue: | | if residue: |
| return word[2*slice_length + 1 :] | | return word[2*slice_length + 1 :] |
| else: | | |
| return word[-slice_length :] | | return word[-slice_length :] |
| | | |
| | | |
| def split_sentence(sentence): | | def split_sentence(sentence): |
| if type(sentence) is not str: | | if type(sentence) is not str: |
| print(f"{sentence} isn't a string. Try again.") | | print(f"{sentence} isn't a string. Try again.") |
| return None | | return None |
t | else: | t | new_sentence = [] |
| new_sentence = sentence.split() | | for word in sentence.split(): |
| for word in range(len(new_sentence)): | | new_sentence.append((beginning(word), |
| new_sentence[word] = ( | | middle(word), |
| beginning(new_sentence[word]), | | end(word))) |
| middle(new_sentence[word]), | | |
| end(new_sentence[word]) | | |
| ) | | |
| return new_sentence | | return new_sentence |