What do we actually need to do in the last additional “challenge”

I just have one question.
What do we actually need to do in the last additional “challenge” (attendance dictionary)?
Should we just create an empty dict in init or do we have to pass in keys and values somewhere?
help would be greatly appreciated. :slight_smile:

Please post the URL to this exercise so we can read the instructions and test some approaches.

1 Like

sorry @mtf
Here is the URL:
https://www.codecademy.com/courses/learn-python-3/lessons/data-types/exercises/review
Thanks for your response!

Yes, as the initial value for a new attribute, attendance

self.attendance = {}

Then we could create a new method, set_attendance that takes one argument, a boolean.

pieter.set_attendance(True)

For my program it would have to be performed daily since I use the datetime object to draw out the date. So at the top of your code, before any class definitions add this line,

from datetime import datetime

If you are not familiar with this module then the best thing to do is read up on it… docs.python.org

The datetime class has a .now() method that returns a datetime object we can disassemble…

now = datetime.now()
year = now.year
month = now.month
day = now.day

Since our attribute is a dict object, we can subscript the date to create a new key, which will then take the value in the argument.

self.attendance[...] = value

We can use any manner of formatting in the subscript but I find the new f-string to be the simplest.

self.attendance[f'{now.year}/{now.month}/{now.day}'] = value
2 Likes

mtf’s response above mine is superb and detailed, per usual. In fact, I read threw this one a few times as well as his responses on this same topic in at least two other threads, while trying to grasp my own understanding of this problem.

It ended up really helping me (and this is not the first time I’ve discovered this approach helpful for me) to take a step back and set up my code to manually add Pieter’s attendance for today to the new attendance empty dictionary that we defined as an instance variable of the Student class. I found that doing it manually at first and then piecing together how to build the method in our Student class really helped me. I thought I’d share that, in case this approach might help you too.

2 Likes

Thanks for sharing man!
This is really a great method to break down difficult parts of a task into small and doable pieces. I appreciate your help.
Have a nice one! :slight_smile:

Thanks @mtf!
I got it. You really help out a lot of people here on Codecademy!
Thanks for your support! :slight_smile:

2 Likes