How would I make this code run completely without error so that age is assigned correctly according to the date they enter?
<pre><code>from random import randint
def main():
    dob = int(input("Please enter the year you were born"))
    if dob &gt; (2005):
        main()
    elif dob &lt; (2004):
        main()
    else:
        def mob():
            if dob == (2004):
                month = input("Please enter the first three letters of the month you were born")
            if month == ("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 == ("Aug","AUG","aug"):
                day = int(input("Please input the day you were born"))
                if day &lt; 28:
                    age = 12
                elif day == ("29","30","31"):
                    age = 11
                else:
                    age = 12
            else:
                age = 11
                if dob == (2005):
                    age = 11
       mob()
main()
</code></pre>

<p>If I were to enter 2004 and then 'aug', it would not ask the day of birth.The code would stop. I also want the code to run so that if I were to enter 2005, it would assign age to 11</p>

<p>Something like this does what you need, I think, though you could tidy it further to give the actual age, by using datetime.</p>

<pre><code>def main():
    yob = int(input("Please enter the year you were born"))
    if yob &gt; 2005:
        return  "Under 11" 
    elif yob &lt; 2004:
        return  "Over 12"
    elif yob == 2004:
        return 12
    else:
        mob = input("Enter a three letter abbreviation for your month of birth: "
        if mob.lower() in ("jan", "feb", "mar", "apr", "may", "jun", "jul"):
            return  12
        elif mob.lower() == "aug":
            dob = int(input("Enter your day of birth"))
            if dob &lt; 28:
                return  12
            elif dob &gt; 28:
                return  11
        else:
            return  11

age = main()
</code></pre>

<p>Better alternative, covers most eventualities I think</p>

<pre><code>from datetime import datetime

def give_age():
    today = datetime.today()
    dob = input("Enter your date of birth (DD/MM/YYYY): ")
    try:
        dob_datetime = datetime.strptime(dob, "%d/%m/%Y")
        age = (today - dob_datetime).days / 365
        return age
    except ValueError:
        print("Your date of birth was not in the required format")
        give_age()
age = give_age()
</code></pre>

python python-3.x