Apr-24-2023, 07:31 AM
(This post was last modified: Apr-24-2023, 08:03 AM by Gribouillis.)
Hello
I want to try to calculate the age in years but in de output i get 1 day instead of 1 year
John 1 day, 0:00:00
What I want is
John 1 Year
I want to try to calculate the age in years but in de output i get 1 day instead of 1 year
from datetime import datetime, date class persoon: def __init__(self, naam, sekse, geboortedatum): self.naam = naam self.sekse = sekse self.geboortedatum = datetime.strptime(geboortedatum, '%d-%m-%Y').date() def getNaam(self): return self.naam def getGebDatum(self): return self.geboortedatum def isVrouw(self): if self.sekse == "V": return True else: return False def isMan(self): if self.sekse == "M": return True else: return False def leeftijd(self): today = date.today() age = (today - self.geboortedatum) // 365 return age p1 = persoon("John", "M", "24-04-2022") print(p1.getNaam(), p1.leeftijd())Output
John 1 day, 0:00:00
What I want is
John 1 Year
Gribouillis write Apr-24-2023, 08:03 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.