Write a function, repeat_letters_in_each_word_in(sentence), which takes a Senten
ID: 3867628 • Letter: W
Question
Write a function, repeat_letters_in_each_word_in(sentence), which takes a Sentence of words consisting entirely of letter separated by a single space and ending with a period, and returns a sentence of words separated by a single space and ending with a period, where each word has its letters repeated. Uses repeat_letters_in(word) as a helper function. Sample run: Sentence = 'Brevity is the soul of wit.' print('Original sentence: ', Sentence) print('Sentence with repeat letters in each word: ') print(repeat_letters_in_each_word_in(sentence)) Original sentence: Brevity is the soul of wit. Sentence with repeat letters in each word: Brreeevvvviiiiittttttyyyyyyy iss thheee soouuullll off wiittt. > > >Explanation / Answer
#!usr/bin/python
def repeat_letters_in_each_word_in(sentence):
list = sentence.split()
for i in range(len(list)):
print(repeat_letters_in(list[i]),end = ' ')
print()
def repeat_letters_in(word):
str = ""
for i in range(len(word)):
str1 = word[i]
if word[i] == '.':
str = str + '.'
continue
for j in range(i):
str1 = str1 + word[i]
str = str + str1
return str
sentence = "Brevity is the soul of wit."
print("original sentence:" + sentence)
print("Sentence with repeat letters in each word:")
repeat_letters_in_each_word_in(sentence)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.