Skip to content
Permalink
Browse files
Update recursive.py
Description of code.
  • Loading branch information
raib10 committed Apr 7, 2021
1 parent 737338b commit 533584c4bf2ea12a2a0c14b53efdce003fe4fc29
Showing 1 changed file with 2 additions and 2 deletions.
@@ -1,8 +1,8 @@
def reverse_word(x):
if len(x) == 1:
if len(x) == 1: # If the input word reversed is the same, then input will be printed out as the result.
return x
else:
return reverse_word(x[1: ]) + x[0]
return reverse_word(x[1: ]) + x[0] # Puts the 0 index of the string at the last index, minus the 0th index the remaining letters will be reveresed.

x = input("Enter a word to reverse: ")
answer = reverse_word(x)

0 comments on commit 533584c

Please sign in to comment.