Skip to content

Modelcode-ai/email-slicer-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Email Slicer Using Python

Email Slicer is a simple tool where the email address is provided as an input and the application returns the username and the domain of the email address as an output. It makes use of the slicing operation in Python.

Built With

Python

Example

Input:

Please enter your Email Id:
[email protected]

Output:

Your username is: avimax37
Your domain is: gmail.com

Here we got avimax37 as username and gmail.com as domain.

Installation

Use the link to download Python.

Python

Use the link to download PyCharm.

PyCharm

Use the link to download Visual Studio Code.

Visual Studio Code

Usage

Open Command Prompt or Windows PowerShell to start.

# get into python mode
python

# create a python script
hello.py
print("Hello World")

# go to the file path
cd <file path>

# run the script
python hello.py

VS Code or PyCharm can also be used.

Code

So at first we are going to ask the user to enter the email that is to be sliced.

print("Please enter your Email Id:")
email = input().strip()

Here, as usual, we are making use of the input() function to get the input from the user in form of a string. We will store this input string in email variable.

Also we are making use of the strip() function. strip() function will remove any additional & unwanted spacing on both sides of the input string. So that we can make sure that we have only the email in the input and not any unwanted spaces.

if email.find("@") != -1:

Here we are checking if the input string contains @ or not. If it contains @, then it is considered as a valid email id and we move to the next step, which is slicing the email.

username = email[:email.index("@")]
domain = email[email.index("@") + 1:]

Now, we print the username and domain to show the result.

print("Your username is: ", username)
print("Your domain is: ", domain)

If the input string does not contain @, then it is considered as an invalid email id and we get out of the loop with a warning message.

else:
     print("Please enter a valid Email Id.")

Logic

Let's consider the input is [email protected], so when we write email[email.index("@"):], our index() function will interpret it as email[:8] as our @ is located at index 8. Now email[:8] knows that @ is located at index 8, so now it will keep the part before index 8 and discard the rest. It will store the stripped value in username.

This exact same process is followed for domain also.

License

Distributed under the MIT License. See LICENSE.md for more information.

Contact

Avinaba Bera

Twitter LinkedIn

Project Links

GitHub

About

Email Slicer is a simple Python3 mini-project. Into this tool email address is provided as an input and the username and the domain is returned as output.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%