Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Age Calculator.py → AgeCalculator.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Calculate the complete age of a person in years, months and days
import datetime
def calculate_age(born):
today = datetime.date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
def main():
# Get the date of birth
dob = input("Enter your date of birth (YYYY-MM-DD): ")
# Split the date into year, month and day
year, month, day = map(int, dob.split('-'))
# Calculate the age
age = calculate_age(datetime.date(year, month, day))
# Print the age
print("Your age is: {}".format(age))
if __name__ == '__main__':
# Calculate the complete age of a person in years, months and days

import datetime

def calculate_age(born):
today = datetime.date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

def main():

# Get the date of birth
dob = input("Enter your date of birth (YYYY-MM-DD): ")

# Split the date into year, month and day
year, month, day = map(int, dob.split('-'))

# Calculate the age
age = calculate_age(datetime.date(year, month, day))

# Print the age
print("Your age is: {}".format(age))

if __name__ == '__main__':
main()