Wednesday, 29 December 2021

To print the words starting with a particular alphabet in a user entered string.

 

Python program:

1
2
3
4
5
6
7
8
9
10
11
s = input("Enter any sentences : ")
a = input("Enter any alphabet to find :")
found = False
words = s.split()
for word in words:
    if word.startswith(a):
        print(word)
        found = True
    if (found == False):
        print("No word starting with user entered alphabet")
    

Output

Enter any sentences : hello athang whats up
Enter any alphabet to find :h
hello


Enter any sentences : today is holiday ,we can take rest today
Enter any alphabet to find :t
today
take
today

No comments:

Post a Comment