PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#This code showcases two simple ways to reverse a string in Python
a=str(input())
#The standard way is the [::-1]
def standard(a):
a=str(a[::-1])
return(a)
b=standard(a)
#The other way employs recursion
def recursion(b):
if len(b)<=1:
return b
return recursion(b[1:])+b[0]
c=recursion(b)
#This part is a bonus to check if the string is a palyndrome, since we do the reversal twice anyway :)
def is_palyndrome(b,c):
return b==c
print("Reversed: "+b)
print("Reversed again: "+c)
if is_palyndrome(b,c):
print("Your word is a palyndrome!")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run