0
484views
write a python program to check if last three characters are same
1 Answer
written 2.6 years ago by | • modified 2.6 years ago |
Code
string=input("Enter the Sentence:- ")
#remove the special char from the string or else it would also be considered as the character
new_string = ''.join(char for char in string if char.isalnum())
#extract last three characters of the string
char=new_string[-3:]
print("Last three characters are:-",char)
#compare if all the characters are same
if (char[0]==char[1]==char[2]):
print("Last three characters are same")
else:
print("Last three characters are different")
Output:-