Question
Python question: Date Clients for the previous problem (ps11pr2) please refer to https://www.chegg.com/homework-help/questions-and-answers/methods-python-class-date-class-stores-manipulates-dates-represented-day-month-year-constr-q13439755 Thank you! Now that you have written a functional Date class, we
Python question: Date Clients
for the previous problem (ps11pr2) please refer to
https://www.chegg.com/homework-help/questions-and-answers/methods-python-class-date-class-stores-manipulates-dates-represented-day-month-year-constr-q13439755
Thank you!
Now that you have written a functional Date class, we will put it to use! Remember that the Date class is only a blueprint, or template, for how Date objects should behave. We can now create Date objects according to that template and use them in client code.
Getting started To start, open a new file in IDLE and save it as ps11pr3.py. Put all of the code that you write for this problem in this file. Dont forget to include appropriate comments at the top of the file, and a docstring for your function.
IMPORTANT: Since your clients will need to construct Date objects, you need to import the Date class. Therefore, make sure that ps11pr3.py is in the same directory as ps11pr2.py, and include the following statement at the top of ps11pr3.py:
from ps11pr2 import Date
Your tasks
Write a function named get_age_on(birthday, other) that accepts two Date objects as parameters: one to represent a persons birthday, and one to represent an arbitrary date. The function should then return the persons age on that date as an integer.
Notes:
You can assume that the other parameter will represent a date on or after the birthday date.
It may be helpful to construct a new Date object that represents the persons birthday in the year of other. That way, you can determine whether the persons birthday has already passed in the year of other, and use that information to calculate the age.
Example:
>>> birthday = Date(6, 29, 1994) >>> d1 = Date(2, 10, 2014) >>> get_age_on(birthday, d1) 19 >>> d2 = Date(11, 10, 2014) >>> get_age_on(birthday, d2) 20
Write a function print_birthdays(filename) that accepts a string filename as a parameter. The function should then open the file that corresponds to that filename, read through the file, and print some information derived from that file.
More specifically, the function should assume that the file in question contains information about birthdays in lines of the following format:
name,month,day,year
In other words, each line of the file contains comma-separated birthday data.
The function should read this file line-by-line, and print the persons name, birthday, and the day of the week on which the person was born in the following format:
name (mm/dd/yyyy) (day)
For example, the file birthdays.txt contains the following data:
George Washington,2,22,1732 Abraham Lincoln,2,12,1809 Susan B. Anthony,2,15,1820 Franklin D. Roosevelt,1,30,1882 Eleanor Roosevelt,10,11,1884
Therefore, calling print_birthdays with this filename should print the following information:
>>> print_birthdays('birthdays.txt') George Washington (02/22/1732) (Friday) Abraham Lincoln (02/12/1809) (Sunday) Susan B. Anthony (02/15/1820) (Tuesday) Franklin D. Roosevelt (01/30/1882) (Monday) Eleanor Roosevelt (10/11/1884) (Saturday)
Notes:
For full-credit, the format of the printed text should exactly match the formatting scheme described above, including spaces and parentheses.
You should process the text file using the line-by-line technique shown in lecture.
For every line of the file, you will need to create a Date object and invoke the appropriate methods on the object to get the information needed.
Originally, the components of the date that you obtain from the file will be in string form. You will need to convert them to integers before you pass them into the Dateconstructor, and you can use the int function for this purpose.
You can get a string representation of a Date object named d using the expression str(d).
Remember that you can concatenate strings together using the string concatentation operator (+). This operator will be helpful when you try to wrap parts of the output in parentheses. For example:
>>> '(' + 'foo' + ')' '(foo)'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started