Created
June 6, 2018 18:38
-
-
Save TomColBee/4cf607f2e5b0e7b703b4d343d6a6c4e8 to your computer and use it in GitHub Desktop.
Python Bible: Email Slicer - String Index, Format and Print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
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()
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
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
def checkCom():
com = ""
try:
for k in range(mail_list.index("@")):
username_list.append(mail_list[k])
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)))