Extract the name from the email address

In this program, we will take email as string input and extract the name from the email address.

Steps to solve the program
  1. Take an email id of a student as string input.
  2. Find the index number of “@” using index().
  3. Create an empty string.
  4. Add characters from the email id to the empty string using for loop up to the index of “@”.
  5. Add only alphabets not numbers use isalpha() for this purpose.
  6. Print the output.
				
					#Input string
str1 = "student1@gmail.com"
index = str1.index("@")
str2 = ""

for char in str1[:index]:
    if char.isalpha():
        str2 += char
        
#Printing output
print(str2)
				
			

Output :

				
					student
				
			

add two strings as they are numbers

count the number of leap years within the range of years

Leave a Comment