In: Computer Science
Using python:
Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True"
Source code of the program and its working are given below.Please go through the comments for better understanding the code.In python indentation is very important, so type code carefully.Screen shot of the code and output are also attached.If find any difficulty,feel free to ask in comment section.Please do upvote this answer.Thank you.
Working of the program
Source code
#prompt user to enter a string and read
#this string into variable st
st=input("Enter the string: ")
# checking first and last character are same
if st[0] == st[len(st)-1]:
#if yes print True
print("True")
Screen shot of the code
Screen shot of the output