Python function that corrects a email domain
Question: Okay, I have this function **construct_email(name, domain):**

    
    
    def construct_email(name, domain):
        if domain == True:
            print 'True'
        else:
            print'None'
        return name + "@" + domain
    

This function isn't big or anything, it's suppose to output an email address.
But I also have this other function `correct_domain(domain):` that is suppose
to check the domain name that's been input in `construct_email(name, domain):`

    
    
    import re
    def correct_domain(domain):
        if re.search(r'^\.|\.$', domain) or re.search(r'\.\.', domain):
            return False
        elif re.search(r'\.', domain):
            return True
        else:
            return False
    

My question is, how do I do this?


Answer: If I'm understanding you correctly:

    
    
    import re
    
    def construct_email(name, domain):
        if not check_domain(domain):
            return False
        return name + "@" + domain
    
    def check_domain(domain):
        dots = re.findall(r"\.", domain)
        if (len(dots) != 1) or domain.startswith(".") or domain.endswith("."):
            return False
        return True
    
    def main():
        while True:
            email = construct_email(raw_input("Name: "), raw_input("Domain: "))
            if email:
                break
            print "Bad Domain, try again...\n"
    
        print email
        #other code here...
    

