Reputation: 1
I have to make a code that splits the username by the domain.
ex.
Input: [email protected]
Output: Your username is abc. Your domain is xyz.com.
The outcome is suppose to by in two different lines but i can't seem to get that...
def username2(email):
z=(email.split('@'))
x='Your username is'+ ' ' + z[0]
y='Your domain is' + ' ' + z[1]
return x+'. '+y+'.'
Sorry.. I'm really noob.
Upvotes: 0
Views: 62
Reputation: 136
Python3
def username2(email):
username, domain = email.split('@')
print('Your username is {}'.format(username))
print('Your domain is {}'.format(domain))
Python2
def username2(email):
username, domain = email.split('@')
print 'Your username is %s' % username
print 'Your domain is %s' % domain
Upvotes: 0
Reputation: 18261
Escape codes are what you're looking for
print "first line \nSecond Line"
http://docs.python.org/2/reference/lexical_analysis.html#literals
Upvotes: 1
Reputation: 298046
You need to insert a newline character into your result:
return x + '. \n' + y + '.'
You could also use string formatting:
username, domain = email.split('@')
return 'Your username is {}.\nYour domain is {}.'.format(username, domain)
Upvotes: 4