If you don’t see your question here, post it on Piazza or come to office hours! See the links in the navigation bar for both of those options.
I keep getting a NoneType
error. Why does this happen?
If your dates are suddenly becoming None
and you do not know
why, check over your code to make sure that you are not assigning
the result of the advance_one
method to a variable.
x = d.advance_one() # incorrect self = self.advance_one() # incorrect
Remember, advance_one
does not return a value. We call it to
modify an object, and we do not want it to return anything.
As a result, you should not assign the result of a call to
advance_one
to a variable. If you do, that variable will end up
with a value of None
(a special value that is returned when a
function does not explicitly return a value), and that can then
lead to a NoneType
error.
Instead, all of your calls to advance_one
should occur all by
themselves on their own lines:
d.advance_one() # correct self.advance_one() # correct
The logic of my days_between
method looks right, but it’s
giving the wrong answer. Do you have any suggestions?
The days_between
method should use other methods from your
Date
class. If your logic in days_between
seems correct but
you are still getting the wrong answer, you should check your
methods from earlier in the problem to see if they are
correct. For instance, try is_before
with two different Date
objects from the same year and month. Does the result seem right?
What about for two Date
s in different months?
My days_between
method hangs (i.e., it keeps running indefinitely
without giving me a return value)
when I call it for certain dates. What could the problem be?
The problem could be in your advance_one
method. Make sure that
it actually advances the date in all possible cases. In
particular, if you are using an if-elif
statement, you may want
to add an else
case to ensure that the date is advanced no
matter what. If advance_one
fails to advance the date in
certain cases, then your days_between
method can end up in an
infinite loop, which causes the method to hang.
Another thing worth checking is whether your days_between
method
may be incorrectly advancing its copy of the later of the two
dates, rather than its copy of the earlier of the two dates. This
can happen if your is_before
method is not returning the correct
value when it compares the two dates in question.
Is it good enough if my Date
methods pass the test cases given
in the assignment?
No! Even if your Date
methods pass the test cases given in the
assignment, they may still be incorrect. We highly recommend
thinking of your own test cases to ensure that your Date
methods
work properly. If you find a case in which a method gives
invalid results, use temporary print
statements to figure out where
the unexpected behavior occurs.
How do I start Problem 2?
If problem 2 seems unclear, read over the relevant lecture slides.
We have already given you a partial
implementation of the create_dictionary
function in those notes.
The first thing you need to do is add code that will read all of the
file’s text as a single string, and then split it into a list of words.
You may want to consult a similar function from lecture
or from Lab 10, Task 3 to see how to do this.
Then use the rest of the code skeleton from the lecture notes, adding whatever code is needed to that skeleton.
The lecture notes also include suggestions and pseudocode for the
generate_text
function.
Last updated on April 28, 2025.