Question: Can you please answer this question in python 3.6 full solution! Thank you! Purpose: To practice recursion with a wrapper function Degree of Difficulty: Easy
Purpose: To practice recursion with a wrapper function Degree of Difficulty: Easy In the lecture slides. you may have attempted an exercise to print out all the characters in a string in reverse using recursion. For this question, you'll tackle a similar task printing out all of the WORDS in a string in reverse. You can assume that separate words in a string are always separated by at least one space Sample Run Assuming our original sentence was DO I CHODSE YOU PIKACHU your function should produce the follo ing output PIKACHU YOU CHOOSE I DO All of the words should be printed on the same line. It is okay if you end up having a trailing space after the last word Program Design When you write programs to solve problems using loops, very often the code doesn't jump right into a loop first thing. Often, there's a bit of set-up that happens first. The same can be true of recursion To solve this problem, you should write TVO functions The first function should be called something like reverse phrase) and must have a SINGLE parameter the string that represents the sentence to be reversed. This function should not itself be recursive. It simply does any necessary set-up before calling your second (recursive) function, which is where the real work will be done Your second function should be called something like reverse.phrase recursive). It can have any num- ber of parameters that you think you need. and those parameters can be of any data type that you think will be easiest to work with This function must be recursive and is not allowed to use loops in any way To test your program, the main part of your program should simply call reverse.phraseO with the string you want to reverse as an argument What to Hand In .A document called a7q2.py containing your finished program, as described above Be sure to include your name, NSID, student number course number and lecture section and laboratory section at the top of all files Evaluation .1 mark: The wrapper function reverse phraseO performs some reasonable setup that makes the recursive function easier to write. e1 mark: The base case of the recursive function is correct 1 mark: The recursive function has reasonable parameters for solving the problem . 2 marks: The recursive case of the recursive function has the correct behaviour . -2 marks Global variables and/or loops are used in the recursive function 2 marks The doc-string for BOTH functions is suficienty descriptive, indicating its purpose and re- quirements
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
