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.
Create a variable daystobreak 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 :: timestamp. daystobreak will
be a timedelta value a difference in time not a string! pt
Define a function whencanvoteus 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 ie when they turn years oldpt
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.
Demonstrate your whencanvoteus function works by printing out when someone born today will be able to vote. pt
Define a function makebirthdayannouncement 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 NAMEs bir thday is in N days" replacing NAME with the
argument, and with the number of days from today until the person's next birthdaypt
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 eg timedifference. 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 dateyour 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!
Create a variable mybdayannouncement by calling your makebir thdayannouncement function and passing in your name use
your existing variable! and your birthdate. Print the variable after you create itpt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
