2014-11-06 39 views
-2

我正在尝试编写一个程序,它接收用户的电子邮件并打印与其关联的URL。到目前为止,我有这样的:使用字符串拼接从电子邮件中提供URL?

def email_intake(): 
    '''Takes email input from the user''' 
    email = input('Enter your email: ') 
    if email.find('@'): 
     return(email) 

    else: 
     print('Please enter a valid email address') 
     email = input('Enter your email: ') 



def find_domain(email): 
    '''Figures out domain name associated with email provided by the user''' 
    domain = email.split('@')[1] 
    return (domain) 




def url_printer(domain): 
    '''prints URL associated with the email provided by the user''' 
    print('The domain of this email address is http//:www. ', domain) 


def main(): 
    email = email_intake 
    domain = find_domain(email) 
    url_printer(domain) 


main() 

我知道,我必须做一些字符串拼接找出我的第二个功能,但我不知道在哪里何去何从。我想知道是否有某种方式可以从@角色收集信息给我。如果这是有道理的。谢谢!

+0

到目前为止你有尝试过什么吗? – ptierno 2014-11-06 04:30:37

回答

0

你是什么意思的网址?如果你在谈论电子邮件的域名,通常在'@'之后直到末尾

你的find_url方法可能看起来像这样。

def find_url(email): 
    return email.split('@')[1] 

P.S:假设您已经验证了以前的email_intake方法中电子邮件的有效性。

+0

是的,我的意思是域名。我不断收到一个错误,说“AttributeError:'函数'对象没有属性'拆分” – 2014-11-06 18:35:55

相关问题