2014-11-06 57 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

相關問題