I am practicing by creating an age calculator which calculates age in years based on given date of birth.
However it doesn't work the way I intend it to function. I want to show age in year e.g 19 to the user when their age is 19 and month is less than 6 and if the month is more than 6 then I want to add 1 to the age in this case 19+1.
Can anyone create the same program with the same concept in a better way? Please add some explanation so that it is easy for me to understand.
I am python beginner, so please excuse my bad code as well as my bad English. Thanks in advance for the help.
from datetime import date
Doby,Dobm,Dobd =input("enter your DOB : i.e year,month,days 1999,02,08 : ").split(",")
born = date(year = int(Doby) , month= int(Dobm) , day= int(Dobd))
today = date.today()
age = today.year - born.year
condition = today.month - born.month
if condition >= 6 :
age += 1
elif condition <= -6 :
age -= 1
print(age)