Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@mdmahikaisharme

This comment has been minimized.

Copy link

@mdmahikaisharme mdmahikaisharme commented Oct 23, 2020

Thanks!

@KyawGyi123851

This comment has been minimized.

Copy link

@KyawGyi123851 KyawGyi123851 commented Feb 10, 2021

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)

@mfischercodes

This comment has been minimized.

Copy link

@mfischercodes mfischercodes 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

This comment has been minimized.

Copy link

@yasinbrcn yasinbrcn commented May 11, 2021

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

This comment has been minimized.

Copy link

@yasinbrcn yasinbrcn commented May 13, 2021

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

This comment has been minimized.

Copy link

@tavityrael tavityrael commented Jun 19, 2021

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()

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