From 7c7857a4628fe7b93ff3232de5389f0cf517731f Mon Sep 17 00:00:00 2001 From: William Mantly Date: Sun, 24 Sep 2023 21:00:03 +0000 Subject: [PATCH] Update 03-birthday/convert.py --- 03-birthday/convert.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/03-birthday/convert.py b/03-birthday/convert.py index 198e821..bae18a5 100644 --- a/03-birthday/convert.py +++ b/03-birthday/convert.py @@ -1,5 +1,26 @@ -def age_to_time(age): - pass +from datetime import datetime -def birthday_to_time(birthday): - pass +def to_time( delta ): + months = int( delta.days/30 ) + days = delta.days + hours = delta.days*24 + minutes = delta.days*24*60 + + return 'months : {}, days : {}, hours : {}, and minutes : {}'.format( months, days, hours, minutes ) + +def age_to_time( age ): + delta = datetime.now() - datetime.now().replace( year=datetime.now().year-age ) + + return to_time( delta ) + +def birthday_to_time( birthday ): + birthday = datetime.strptime( birthday, "%Y-%m-%d" ) + delta = datetime.now() - birthday + + return to_time( delta ) + +age = int( input('How old are you? ') ) +print( age_to_time(age) ) + +birthday = input( 'What is your birth date?(YYYY-MM-DD) ') +print( birthday_to_time(birthday) ) \ No newline at end of file