Skip to content

Instantly share code, notes, and snippets.

@shamikalashawn
Created February 9, 2017 20:03
Show Gist options
  • Save shamikalashawn/5c606d6f327f9a8e9cfb6d22a98c4bf4 to your computer and use it in GitHub Desktop.
Save shamikalashawn/5c606d6f327f9a8e9cfb6d22a98c4bf4 to your computer and use it in GitHub Desktop.
Give this app your birthday and it will tell you how many days until your birthday, how many have passed since your birthday, or happy birthday!
from datetime import datetime
def print_header():
print ('---------------------------------------------' + '\n' + ' BIRTHDAY APP' + '\n' + '---------------------------------------------' + '\n')
def get_birthday_from_user():
year = int(input('What year were you born [YYYY]?: '))
month = int(input('What month were you born [MM]?: '))
day = int(input('What day were you born [DD]?: '))
bday = datetime(year, month, day)
return bday
def compute_days_between_dates(birthday, today):
date1 = datetime(today.year, birthday.month, birthday.day)
dt = date1 - today
wait = int(dt.total_seconds()/60/60/24)
return wait
def print_birthday_information(bday, wait):
print('It looks like you were born on {0:%B %d, %Y}.'.format(bday))
if wait > 0:
print('Looks like your birthday is in {} days.'.format(wait))
print("Hope you're looking forward to it!")
elif wait == 0:
print('Looks like your birthday is today! Happy birthday.')
elif wait < 0:
print('Looks like your birthday passed {} days ago.'.format(-wait))
print('Hope you enjoyed it!')
def main():
print_header()
bday = get_birthday_from_user()
now = datetime.now() #current time
number_of_days = compute_days_between_dates(bday, now)
print_birthday_information(bday, number_of_days)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment