Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a python program that modifies the words in a string variable. Create stri

ID: 3827796 • Letter: W

Question

Write a python program that modifies the words in a string variable. Create string variable and assign a sentence. Example: aString = "Michelle ma belle these are words that go together well" {Ref: The Beatles} Your program should generate another string variable and print it. The modifications should be as follows 1 - odd indexed (1st 3rd 5th etc.) words should be converted to upper case 2 - even indexed (2nd 4th 6th etc.) words should be reversed, the output would be as follows bString = "MICHELLE am BELLE eseht ARE sdrow THAT og TOGETHER llew " You can use user - defined functions if you need or you can write your program without any user - defined functions

Explanation / Answer

def cap_and_reverse(string):
words = string.split()
result = []
for i in range(0, len(words)):
if i % 2 == 0:
result.append(words[i].upper())
else:
l = list(words[i])
l.reverse()
result.append("".join(l))
return " ".join(result)

aString = "Michelle ma belle these are words that go together well"
bString = cap_and_reverse(aString)
print(bString)

# code link: https://pastebin.com/WrxW89Uv

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote