Skip to content

Instantly share code, notes, and snippets.

@TomColBee
Created June 6, 2018 18:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TomColBee/4cf607f2e5b0e7b703b4d343d6a6c4e8 to your computer and use it in GitHub Desktop.
Save TomColBee/4cf607f2e5b0e7b703b4d343d6a6c4e8 to your computer and use it in GitHub Desktop.
Python Bible: Email Slicer - String Index, Format and Print
# Get user email address
email = input("What is your email address?: ").strip()
# Slice out the user name
user_name = email[:email.index("@")]
# Slice the domain name
domain_name = email[email.index("@")+1:]
# Format message
output = "Your username is '{}' and your domain name is '{}'".format(user_name,domain_name)
# Display output message
print(output)
Copy link

ghost commented Oct 23, 2020

Thanks!

@KyawGyi123851
Copy link

email_address = input('Enter your email address : ')
position = email_address.index('@')
output = ''
counter = 0
for ch in email_address:
if counter > position:
output += ch
counter += 1
if output == 'gmail.com':
result = "I see your email is registered with Google. That's cool!."
else:
result = "looks like you've got your own custom setup at MyFantasy. Impressive!."
print(result)

@themichaelfischer
Copy link

themichaelfischer commented Feb 17, 2021

popular_domains = {
"gmail": "Google",
"hotmail":"Microsoft",
"yahoo":"Yahoo",
"outlook":"Microsoft"}

user_email = input("What is your email address? ")

user_name = user_email.split('@')[0]
user_domain = user_email.split('@')[-1]
user_domain = user_domain.split('.')[0]

if user_domain in popular_domains.keys():
print(f"Hey {user_name} it seems like your email is registered with {popular_domains[user_domain]}!")
else:
print(f"Hey {user_name} it seems like you have your own custom domain at {user_domain}!")

@yasinbrcn
Copy link

j=1
mail_list = []
username_list = []
domain_list = []
def listString(s):
string = ""
for n in s:
string += n
return string
email = str(input("What is your email address?: "))
for i in range(len(email)):
mail_list.insert(i,email[i:j])
j=j+1

for k in range(mail_list.index("@")):
username_list.append(mail_list[k])

for m in range(mail_list.index("@")+1,len(mail_list)):
domain_list.append(mail_list[m])

print("Hello {}. Your domain adres: {}".format(listString(username_list),listString(domain_list)))

@yasinbrcn
Copy link

I updated my previous code. If the user doesn't enter @ and .com information, I showed an error message. I asked the user for a valid e-mail address.

key=1
mail_list = []
username_list = []
domain_list = []
com_list = []

def listString(s):
string = ""
for n in s:
string += n
return string

def checkEmail(e):
j=1
for i in range(len(e)):
mail_list.insert(i,e[i:j])
j=j+1

try:
    mail_list.index("@")!=0
    check = 1
except:
    mail_list.clear()
    username_list.clear()
    domain_list.clear
    com_list.clear()
    check = 0
return check

def checkCom():
com = ""
try:
for k in range(mail_list.index("@")):
username_list.append(mail_list[k])

    for m in range(mail_list.index("@")+1,len(mail_list)):
        domain_list.append(mail_list[m])
        
    for n in range (domain_list.index("."),len(domain_list)):
        com_list.append(domain_list[n])
        com = str(listString(com_list))
except:
    mail_list.clear()
    username_list.clear()
    domain_list.clear()
    com_list.clear()
if com == ".com" and domain_list.index(".") != 0:
    checkcom = 1
else:
    mail_list.clear()
    username_list.clear()
    domain_list.clear()
    com_list.clear()
    checkcom = 0
return checkcom

while key == 1:
email = str(input("What is your email address?: "))
if checkEmail(email) == 1 and checkCom() == 1:
key=0
else:
print("Invalid email address. Please enter a valid email address.")
mail_list.clear()
username_list.clear()
domain_list.clear()
com_list.clear()
key=1

print("Hello {}! Your domain adres: {}".format(listString(username_list),listString(domain_list)))

@tavityrael
Copy link

name = input('Enter your name: ')
name = name.title()
email = input('Enter your email: ').strip()

def type():
at = email.find('@')
dot = email.find('.',at)
host = email[at + 1 : dot]
print('........................................................')

if host == 'gmail' or host == 'yahoo' or host == 'outlook' or host == 'aol' or host == 'icloud':
    print('Hey ' + name + ', I see your email is registered with ' + host.title() + '. That is cool!')
else:
    print("Hey " + name + ", looks like you've got your own costom setup at " + host.title() + ". Impressive!")

type()

@Lord-Shax
Copy link

import re
def recog():
x = input('enter name and email: ')
match = re.search(r'@[\w-]+', x)
email = match.group(0)
e = email[1:]
print('Oh nice, I see your mail is a', e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment