Code in Python to check last three characters are same

 Code in Python to check last three characters are same

Code:-

#Code in Python to check last three characters are same
string="Our school building is made of bricks."
#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:-

Last three characters are:- cks Last three characters are different

Code:-

#Code in Python to check last three characters are same
string="What is the eligibility for giving III?"
#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:-

Last three characters are:- III Last three characters are same

Post a Comment

0 Comments