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.
This file contains hidden or 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
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
If you have any doubt and suggestion Please let me know