Question: please use python use the python datetime module a ) Class initialisation Set up a class which takes as input the day, month and year

please use python
use the python datetime module
a) Class initialisation
Set up a class which takes as input the day, month and year of birth and sets these as class attributes. The class should also set up a derived attribute, a datetime() object built using the year, month and day. Test that it works when you set it up with a birthday. Print out the year attribute of the class.
b) A first method: days since birth
Let's add a function to the class which returns the days since birth. Note that datetime. datetime. today () will give a datetime object of today's date, and if you subtract two datetime objects you will end up with a datetime.timedelta object. You just need to return the days part of the timedelta object. Use this method and print out the result.
c) A second method: days to birthday
How many days until your birthday? Let's add a method which calculates this and returns the number of days. A procedure for this would go something like the following:
Determine today's date
Set up a datetime object holding your birthday for this year
Check if your birthday this year has already passed, if so, set up a datetime object of your birthday for next year.
Subtract your next birthday from today, to get a timedelta object
Return the days part of the timedelta object
dInitialise a birthday object with the birthday 10/6/1990. Determine the days since birth to the date 23/4/2024, the days to next birthday

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!