In this assignment you’ll practice
datetime.date objects in Python,This is an individual assignment.
Collaboration at a reasonable level will not result in substantially similar code. Students may only collaborate with fellow students currently taking CS 2316, the TA’s and the lecturer. Collaboration means talking through problems, assisting with debugging, explaining a concept, etc. You should not exchange code or write code for others.
Notes:
You are writing a web application to manage a database of Georgia Tech students.
Write a module named gtstudents with the classes and functions specified below.
GtStudent
Write a class called GtStudent with the following instance variables:
gtid: str – 9-digit GT IDgtlogin: str – BuzzPort login idfirst_name: strlast_name: strbirth_date: datetime.datemajor: strhours: int – number of completed semester hoursThese instance variables should all be initialized when you create an instance of GtStudent.
In addition, implement the following methods:
A magic method that gives instances of GtStudent a str representation, whether by passing an instance to the str() function or echoing the value of an instance in the REPL. See the examples below for the format of this string representation.
A magic method that makes it possible to compare two instances of GtStudent for equality using operator == – two instances of GtStudent are equal if all of their instance variables are equal,
A magic method that makes it possible to compare two instances of GtStudent using operator <. A GtStudent is “less than” another if their completed semster hours is less than the other GtStudent’s completed semester hours. If both students have the same hours, then a younger student is “less than” the other.
An instance method named age that that takes no parameters (other than self) and returns the GtStudent’s age in years.
datetime.timedelta class due to leap years. It’s probably easier to use a different approach.An instance method named year that takes no parameters (other than self) and returns the year of the student based on the student’s number of hours, that is (hours // 30) + 1
mk_gtstudents_dict
Write a function called mk_gtstudents_dict which takes a list of GtStudent instances and returns a dictionary mapping GT IDs to the GtStudent instance having that GT ID. If more than one GT ID appears in the list, the subsequent instances may replace earlier ones.
GtStudent instances with the same GT ID, raise an exception with the message “Duplicate GtStudent instances with gtid XXXXXXXXX”, where XXXXXXXXX is the diplicate GT ID.graduating
Write a function called graduating which takes a dictionary mapping GT IDs to GtStudent instances (like the one returned by mk_gtstudents_dict) and returns a list containing all the instances of GtStudent with more than 115 hours.
doctestInclude the docstring below as a module docstring in your gtstudents module so that you can test your code using the doctest module.
python -m doctest -v gtstudents.py
If all the tests pass, then you’ll have a good chance of getting a 100 on this homework. Take a look at these docstests. Are there any edge cases that aren’t tested?
IMPORTANT: The provided doctstrings test the code for the output we expect. If you change these docstrings they may not test your code the way we will test it. We engourage you to add your own docstrings, but we recommend that you leave these docstrings as-is.
>>> import datetime as dt
>>> cartman = GtStudent("123456789", "ecartman3", "Eric", "Cartman", dt.date(2009, 7, 1), "BA", 80)
>>> kenny = GtStudent("223456789", "kmccormick3", "Kenneth", "McCormick", dt.date(2009, 4, 10), "STAC", 80)
>>> stan = GtStudent("323456789", "smarsh3", "Stanley", "Marsh", dt.date(2009, 10, 19), "IE", 85)
>>> kyle = GtStudent("423456789", "kbroflovski3", "Kyle", "Broflovski", dt.date(2009, 5, 26), "CS", 85)
>>> cartman
<Eric Cartman (123456789, ecartman3), a 9 year-old 3rd-year BA major>
>>> str(cartman)
'<Eric Cartman (123456789, ecartman3), a 9 year-old 3rd-year BA major>'
>>> stan == kyle
False
>>> stan2 = GtStudent("323456789", "smarsh3", "Stanley", "Marsh", dt.date(2009, 10, 19), "IE", 85)
>>> stan is stan2
False
>>> stan == stan2
True
>>> cartman < kenny
True
>>> stan < kenny
False
>>> cartman.age()
9
>>> cartman.year()
3
>>> boys = [cartman, kenny, stan, kyle]
>>> boys_dict = {"123456789": cartman, "223456789": kenny, "323456789": stan, "423456789": kyle}
>>> mk_gtstudents_dict(boys) == boys_dict
True
>>> bebe = GtStudent("987654321", "bstevens3", "Barabara", "Stevens", dt.date(2009, 5, 5), "EE", 116)
>>> heidi = GtStudent("887654321", "hturner3", "Heidi", "Turner", dt.date(2009, 6, 2), "PHYS", 117)
>>> annie = GtStudent("787654321", "aknitts3", "Annie", "Knitts", dt.date(2010, 1, 25), "ME", 115)
>>> wendy = GtStudent("687654321", "wtestaburger3", "Wendy", "Testaburger", dt.date(2009, 10, 2), "AE", 114)
>>> girls = [bebe, heidi, annie, wendy]
>>> graduating(mk_gtstudents_dict(boys + girls))
[<Barabara Stevens (987654321, bstevens3), a 9 year-old 4th-year EE major>, <Heidi Turner (887654321, hturner3), a 9 year-old 4th-year PHYS major>]
>>> try:
... mk_gtstudents_dict([cartman] + boys)
... except Exception as e:
... print(str(e))
...
Multiple students with 123456789
datetime moduleGtStudent class with __init__ that initializes all the required instance attributesGtStudet class has magic method that provides correct str representation in REPLGtStudet class has magic method that provides correct str representation str()GtStudet class has magic method that correctly implements value equality for operator ==GtStudet class has magic method that correctly implements operator < when students have different hoursGtStudet class has magic method that correctly implements operator < when students have same hoursGtStudet.age method correctly implementedGtStudet.year method correctly implementedmk_gtstudents_dict correctly implementedgraduating correctly implementedmk_gtstudents_dict throws exception with correct message for first duplicate GT ID in listSubmit your gtstudents.py file on Canvas as an attachment. When you’re ready, double-check that you have submitted and not just saved a draft.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.