Question: Given this string of words: name = 'George Herbert Walker Bush' write a program that rotates the words in the string, such that for each

Given this string of words:
name = 'George Herbert Walker Bush'
write a program that rotates the words in the string, such that for each rotation, the words that was last is now first.
Details:
Write two user defined functions.
The first function, called last2first, will take a multi-word string as argument and move the last word in a multi-word string to the beginning of the string, and then return the string
So for example, if passed the string
George Herbert Walker Bush
the function will return
Bush George Herbert Walker
The second function, called rotate, will use repetition to call the last2first function to rotate the words in the string, such that for each rotation, the words that was last is now first. The rotate function will print the string returned by the last2first function.
The rotation should continue calling the last2first function until the word has been completely rotated, printing each rotation as it goes.
The calling code is as follows:
pres = 'George Herbert Walker Bush'
rotate(pres)
The output will look like this:
George Herbert Walker Bush
Bush George Herbert Walker
Walker Bush George Herbert
Herbert Walker Bush George
There are plenty of ways to do this in Python. A simple solution can be constructed using these list and string methods:
split
pop
insert
join

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!