Don't you find it amazing to discover words and sentences that have the same first and last letter? We just don't usually notice them, so we can try it out by coding out this problem instead! Print out "Yes" if the first and last characters of the given string are the same, and "No" otherwise. It doesn't matter if they're in lowercase or uppercase, as long as it's the same letter, it fits the description.
So, what are you waiting for? Code now!
Input
A line containing a string.
Pop·it·up
Output
A line containing a string.
Yes
#Get string from the User and lower all the characters
string = input("Enter a string: ").lower()
#Check if the string has enough character to compare
#Check if the first character and the last character are the same
if len(string) < 2:
print("Not enough character to compare")
elif string[0] == string[-1]:
print("Yes")
else:
print("No")
Comments
Leave a comment