ask.py: 10 points
In this section, you’ll write a program called
ask.py which gets a series of character names from the user and then prints out a fun story. Your program should contain a recursive function named
ask_around() which, given a list of character names (strings), prints each line of a story about finding some sugar. The story idea we follow here is a common pattern across cultures where a simple phrase repeats multiple times in a nested fashion.
Your final implementation of
ask_around() must be recursive and cannot use any loops. You can assume the user will provide 2 or more characters to the tell story - do not assume a static number though!
Your program should include a
main() function where the user provides as many characters as they like until they enter an empty string - you can use a loop for this functionality in
main(). Then you should call your implementation of
python ask.py should produce the following output:
Please enter at least two character names. Character: Moose Character: Bear Character: Bunny Character: Bee Character: Moose asked Bear if they had any sugar. Bear asked Bunny if they had any sugar. Bunny asked Bee if they had any sugar. Bee had sugar! And Bee gave the sugar to Bunny. And Bunny gave the sugar to Bear. And Bear gave the sugar to Moose.
In this example, the user enters the characters “Moose”, “Bear”, “Bunny”, and “Bee”. Note that the last character in any character list (
Bee in the above example), has a special line announcing that they have sugar.
You may want to think about breaking the task of writing
ask_around() into multiple parts; for each story about a character there is a first sentence and a last sentence where that character is the subject. For example, look at how “Moose” is used in the output above.