Python 3 Write a function that reverses a string the header
Python 3
Write a function that reverses a string. the header of the function is def reverse(s):
Write a test program that prompts the user to enter a string,invokes the reverse function and displays the reversed string
Use a loop, (use a loop, don\'t use [::-1])
Solution
reversestr.py----
str=input(\'enter a string : \')
print \'reverse : \',reverse(str)
def reverse(s):
return s[::-1]
--------explanation------
In the reverse function we used to slice to reverse the string by going backward using -1 (double colon implies to implement reverse slice on the complete string)
