Dremendo Tag Line

Input a name and print its initials in Python

String Methods - Question 4

In this question, we will see how to input a name and print its initials in Python programming. To know more about string methods click on the string methods lesson.

Q4) Write a program in Python to input a name and print its initials.

Example:
Input ->   MOHIT KUMAR AGARWAL
Output ->  M.K.A

Program

str=input("Enter a name\n")

for i in range(0,len(str)-1):
    if i==0 and str[i]!=' ':
        print(str[i],end='')

    elif str[i]==' ' and str[i+1]!=' ':
        print("."+str[i+1],end='')

Output

Enter a name
Mohandas Karamchand Gandhi
The initials of the name is
M.K.G
video-poster