from datetime import date class person: # Initalize the Person object with a name, country, and of birth def init(self,name,country, date_of_birth): self.name = name self.country = country self.date_of_birth = date_of_birth #Calculate the of the person based on their date of birth def calculate_age(self): today = date.today() age = today.year - self.date_of_birth.year if today < date(today.year, self.date_of_birth.month, self.date_of_birth.day): age-=1 return age
person1 = person("Ramu", "ongole", date(2003, 7, 12))
#Access and print the attributes and calculated age for each person print("calculated age for each person") print("********************************") print("person 1:") print("Name:", person1.name) print("Country:", person1.country) print("Date of Birth:",person1.date_of_birth) print("Age:", person1.calculate_age())