Question: Create a variable today that represents the current date. Use the referenced function so that it's accurate whenever the cell is executed. 2 p t

Create a variable today that represents the current date. Use the referenced function so that it's accurate whenever the cell is executed.
2pt
[0]
Create a variable days_to_break that is how many days from the current date until the end of the current quarter. Hint: subtract the date
variables you just made! Print the variable after you create it; your printed output can include a 00:00:00 timestamp. days_to_break will
be a timedelta value (a difference in time), not a string! [2pt]
[0]
Define a function when_can_vote_us() that takes as an argument a birth date (as a date value!). This function should return the date in
which a person born on that day can legally vote in the US (i.e., when they turn 18 years old).[9pt]
In order to calculate this date, you should use the dateutil.relativedelta module. You will need to import the relativedelta function from
this module, which will let you specify a "time change" in terms of years (using a named argument) that can then be added (+) to a date
value. See the examples for details -- look especially at the code examples provided.
[0]
Demonstrate your when_can_vote_us function works by printing out when someone born today will be able to vote. [2pt]
[0]
Define a function make_birthday_announcement () that takes in two arguments: a name (as a string), and a date of birth (as adate--
not a string). This function should return a string of the format "{NAME}'s bir thday is in {N} days" (replacing {NAME} with the
argument, and {N} with the number of days from today until the person's next birthday).[16pt]
This algorithm can be a bit tricky! A few tips:
If you use the relativedelta() function rather than the subtraction operator to produce a "time difference", you'll be able to extract
the number of days or years in that difference by by accessing the .days or . years properties (e.g., time_difference. years).
Once you've determined how many years old the person currently is, you can use that number to figure out the date that they turn one
year older (similar to how you calculated voting age).
You can then calculate the time difference between the their next birthday and today. You can just use normal subtroction to calculate
the difference, because the values are already relativedeltas. You can then access the number of . days in that difference value.
Be sure to use the today () function to get today's current date-your function should work correctly no matter when it is executed.
Other approaches are also acceptable; the goal here is to practice with algorithmic approaches and functions!
[0]
Create a variable my_bday_announcement by calling your make_bir thday_announcement () function and passing in your name (use
your existing variable!) and your birthdate. Print the variable after you create it.[2pt]
[0]
Create a variable today that represents the

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!