An error appears saying a function was referenced before it was assigned but only when I enter the year above 2005 or 2004
<pre><code>x = 2
while x&gt;1:
    from random import randint
    import time
    fn = input("Hello, what is your first name?")
    while any (ltr.isdigit() for ltr in fn):
        fn = input("Sorry an integer was entered, please try again")
    firstname = (fn[0].upper())
    ln = input("Hello, what is your last name?")
    while any (ltr.isdigit() for ltr in ln):
        ln = input("Sorry an integer was entered, please try again")
    lastname = (ln.lower())
    def main():
        dob = input("Please enter the year you were born")
        if dob &gt; ("2005"):
            main()
        elif dob &lt; ("2004"):
            main()
        else:
            def mob():
                if dob == ("2005"):
                    age = 11
                elif dob == ("2004"):
                    month = input("Please enter the first three letters of the month you were born")
                    while month not in ("Jan","JAN","jan","Feb","FEB","feb","Mar","MAR","mar","Apr","APR","apr","May","MAY","may","Jun","JUN","jun","Jul","JUL","jul","Aug","AUG","aug","Sep","SEP","sep","Oct","OCT","oct","Nov","NOV","nov","Dec","DEC","dec"):
                        month = input("Sorry that was incorrect, please enter the first three letters of the month you were born")
                    if month in ("Jan","JAN","jan","Feb","FEB","feb","Mar","MAR","mar","Apr","APR","apr","May","MAY","may","Jun","JUN","jun","Jul","JUL","jul"):
                        age = 12
                    elif month in ("Aug","AUG","aug"):
                        day = input("Please input the day you were born")
                        while day not in("31","30","29","28","27","26","25","24","23","22","21","20","19","18","17","16","15","14","13","12","11","10","9","8","7","6","5","4","3","2","1"):
                            day = input("Please input the day you were born")
                            if day == ("28","27","26","25","24","23","22","21","20","19","18","17","16","15","14","13","12","11","10","9","8","7","6","5","4","3","2","1"):
                                age = 12
                            elif day in ("29","30","31"):
                                age = 11
                        else:
                            age = 12
                    else:
                        age = 11
                else:
                    age = 11
                usernames = []
                age = int(age)
                age2 = age + randint(1,9)
                age2 = str(age2)
                print("Thank you for taking the time to enter your details, your username is now being generated")
                time.sleep(1)
                print("Generating...")
                time.sleep(2)
                username = (dob[2]+''+dob[3]+''+firstname+''+lastname+''+age2)
                print("This is your username:" +''+username)
                usernames.append(username)
                age = str(age)
                with open("Import Usernames.txt", "w") as text_file:
                    print("The usernames are:   {}".format(usernames), file=text_file)
        mob()
    main()
</code></pre>

<p>An error only appears when I enter a year higher than 2005 or lower than 2004 but I don't know why, my question is, what have I done wrong?</p>

<p>This is the error that pops up:</p>

<p>UnboundLocalError: local variable 'mob' referenced before assignment</p>