Write a python Program: To reverse the string and check each word of string is equal or not. If any word is equal print that word index number

 


Ask the user to enter a string . Compare each element of the string. Use indexing to compare strings.In python and c++ indexing start with 0.To see more about index go to the theory section of python.

author="Simulation-Hub"
st=str(input("enter a string :"))
print("You Entered :",st)
rev=st[::-1]# Reverse string
print("Your reverse string is :",rev)
for i in range(len(st)):#for loop running over whole string
if (st[i]==rev[i]):#checking for each word
print("Word ",st[i]," is same")
print("Word index number is ",i)
else:
print("Word at index ",i," is not same ")
enter a string :chiich
You Entered : chiich
Your reverse string is : hciihc
Word at index  0  is not same 
Word at index  1  is not same 
Word  i  is same
Word index number is  2
Word  i  is same
Word index number is  3
Word at index  4  is not same 
Word at index  5  is not same 

0 Comments