209k views
5 votes
Write a function called reverse Return that is almost the same job as reverse, but instead of printing the letters straight to the screen, it returns a String in which the letters have been reversed. The function call would look like:

User Adam Storr
by
7.8k points

1 Answer

0 votes

Answer:

The function in Python is as follows:

def reverse(inputstr):

outputstr = ""

for i in inputstr:

outputstr = i + outputstr

return outputstr

Step-by-step explanation:

This defines the function

def reverse(inputstr):

This initializes the output string

outputstr = ""

This iterates through the input string

for i in inputstr:

This generates the output string by reversing the input string

outputstr = i + outputstr

This returns the reversed string

return outputstr

User Carlos Rojas
by
7.9k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.