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 lastfirst, will take a multiword string as argument and move the last word in a multiword 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 lastfirst 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 lastfirst function.
The rotation should continue calling the lastfirst 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'
rotatepres
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
