0
484views
write a python program to check if last three characters are same
1 Answer
0
15views

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:-

enter image description here

enter image description here

Please log in to add an answer.