Age calculator in python I am new to python and to the StackExchange sites. I made an age calculator but i want to improve it till it's a reliable thing. Can i shorten the code? What can be Done more? Does it need any additions?
Thanks in advence.
from datetime import datetime

print(&quot;A simple program to calculate your age&quot;)
print()

date = datetime.now()
year = int(date.year)
month = int(date.month)
day = int(date.day)
input_year = int(input(&quot;Enter the year you were born: &quot;))
if input_year &lt;= 0 or input_year &gt; 2020:
    print(&quot;don't you know your birthday??&quot;)
    exit()
input_month = int(input(&quot;Enter the month you were born: &quot;))
if input_month &lt;= 0 or input_month &gt; 12:
    print(&quot;don't you know your birthday??&quot;)
    exit()
input_day = int(input(&quot;Enter the day you were born: &quot;))
if input_day &lt;= 0 or input_day &gt; 31:
    print(&quot;don't you know your birthday??&quot;)
    exit()
age_year = year - input_year
age_month = month - input_month
if age_month &lt; 0:
    age_year = age_year - 1
    age_month = 12 - (input_month - month)
age_day = day - input_day
if age_day &lt; 0:
    age_month = age_month - 1
    age_day = 31 - (input_day - day)
print(&quot;you are &quot; + str(age_year) + &quot; years, &quot; + str(age_month) + &quot; months and &quot; + str(age_day) + &quot; days old.&quot;)
Generally, it is often not a good idea to hardcode values. For example, take a look at this piece of code. It won't work correctly from 2021 onwards:
if input_year &lt;= 0 or input_year &gt; 2020:
    print(&quot;don't you know your birthday??&quot;)

Better do it like this:
date = datetime.now()
current_year = int(date.year)

if input_year &lt;= 0 or input_year &gt; current_year:
    print(&quot;don't you know your birthday??&quot;)

This will make your program work in future years without the need to change the value for the current year manually.