DEV Community

Cover image for Cool Python Project 1: Birthday Estimator
Abhi Develops - SunTech
Abhi Develops - SunTech

Posted on

Cool Python Project 1: Birthday Estimator

Hi Everyone! Welcome to Cool Python Projects!
In this post I will be showing you how to make a Birthday Estimator in Python. Please remember to follow me to stay updated on any new projects.

Python Code:

import datetime

def get_birthday_from_user():

   year = int(input('What year were you born? '))

   month = int(input('What month were you born? '))

   day = int(input('What day were you born? '))

   user_bday=datetime.date(year,month,day)

   return user_bday

def compute_days_between_dates(bday2,today2):

   bday2 = datetime.date(today2.year,bday2.month, bday2.day)

   days3 = bday2 - today2

   print(days3, type(days3))

   return days3.days

def print_birthday_information(bday4):

   if bday4 < 0:

       print('Your Birthday was {0} days ago!'.format(-bday4))

def main ():

   user_bday2 = get_birthday_from_user()

   today = datetime.date.today()

   days_to_bday = compute_days_between_dates(user_bday2,today)

   print_birthday_information(days_to_bday)

main()
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed this Python project.

All the projects code in the series

Top comments (0)