user2197034
user2197034

Reputation: 1

separating a line into two in python

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

Answers (3)

Ghost
Ghost

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

David
David

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

Blender
Blender

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

Related Questions