Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
210CT-CW/recursive.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
10 lines (8 sloc)
432 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse_word(x): | |
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] # 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) | |
print("The word",x,"reversed is",answer,".") |