In this article, we will make an email slicer. The task is very simple. We take an email address from the user and we slice the email address to get the username and the domain name. Then, we output the username and the domain name back to the user.
Save the below code in a file named 'email_slicer.py'.
email = input("Email Address: ").strip()
index = email.index('@')
username = email[:index]
domain = email[index+1:]
print("\nEmail address: ", email)
print("Username: ", username)
print("Domain name: ", domain)
In the first line we take the email address as input from the user and then we use the strip to remove any whitespace from the email address.
Then, we find the index of the '@' symbol which is used to separate the username and domain name in the email addresses universally.
We then slice the email address in two parts to get the username and the domain name which is then printed on the console.
To run the program, enter the following command in a Terminal/Command Line
python3 email_slicer.py
A sample output will look like this
Email Address: email@example.com Email address: email@example.com Username: email Domain name: example.com
Comments