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

3 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