Robotics & Artificial Intelligence
Write a Python program for the following task:
Take a string entered by the user and check if it begins with the letter "a" or not. If it begins with "a", the user is prompted that it is the first name on the list. If it does not begin with "a", the user is prompted that the string does not begin with the letter "a".
Python String Manipulation
2 Likes
Answer
string1 = input("Enter a string: ")
if string1.startswith("a"):
print("It is the first name on the list")
else:
print("The string does not begin with the letter a")Output
Enter a string: apple
It is the first name on the list
Enter a string: mango
The string does not begin with the letter a
Answered By
1 Like
Related Questions
Explain any four string operators.
Write a Python program to check that a given string contains only alpha numeric characters. If user is not entering alphanumeric characters prompt him or her to enter it again.
Write a Python program to check that a given string is a palindrome or not.
Write a Python program to reverse a string.