Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Purpose: To practice recursion with a wrapper function Degree of Difficulty: Easy In the lecture slides, you may have attempted an exercise to

Python 3image text in transcribed

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 CHOOSE YOU PIKACHU, your function should produce the follow- 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 TWO 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_phrase) with the string you want to reverse as an argument

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions