I am trying to create a program in Python which takes any entered word and reverses the order, and prints the word in the reverse order. But I am not getting the desired results. Here is the code I am using:
myString = input("Enter any String: ")
length = len(myString)-1
reverse = []
i = 0
while length>=0:
reverse.append(myString[length])
length -=1
while length<0:
break
print(reverse)
reverseString = ''
j = 0
while j<=length:
reverseString +=reverse[j]
j+=1
while j> length:
break
print(reverseString)
In the output, I only see this:
Enter any String: De Costa
['a', 't', 's', 'o', 'C', ' ', 'e', 'D']
and not this as expected: 'atsoC eD'
Where am I going wrong?