Hello, last week our class had a homework assignment in which we created a function which that capitalized all of the even words within a sentence, and reversed each odd word within a sentence. I was wondering, how would I go about using the same for loop I created to simply reverse the entire sentence itself, without capitalizing anything.
Here is the program which I wrote for the homework assignment:
the_sentence(words)
Here is the program which I wrote for the homework assignment:
def the_sentence(words):
sentence = words
new_sent = sentence.split(" ")
for x in range(len(new_sent)):
if x % 2 == 0 :
new_sent[x] = new_sent[x].upper()
else:
new_sent[x]=new_sent[x][::-1]
print(new_sent)words = input("please enter a sentence") the_sentence(words)
