Welcome to the Treehouse Community
Looking to learn something new?
Laurens Sandt3,513 Points
my code is
import datetime year = datetime.timedelta(days=365) another_year = datetime.timedelta(weeks=40, days=84, hours=23, minutes=45, seconds=600) def minutes(year, another_year): return round((year.total_seconds()-another_year.total_seconds())/60) print(minutes(year, another_year))
if you run this in Pycharm I get 5 which is the correct answer
however if give as a solution:
import datetime def minutes(another_year, year): return round((year.total_seconds()-another_year.total_seconds())/60)
I am bummed out
obviously I am going wrong somewhere but where?
Jennifer NordellTreehouse Teacher
Hi there! You're not the first to get tripped up on this question. But the idea here is that they want you to subtract the datetime objects directly. I did it all on one line like this:
import datetime def minutes(another_year, year): return round(((year - another_year).total_seconds()) /60)
This will subtract our datetime objects returning a new datetime object that we can then use our total_seconds method on. Then we divide by 60 and round.
However, if you want a truly superb explanation of this challenge, you should check out this answer by a moderator
Michael Hulet47,881 Points
Admittedly, my knowledge of the
datetime module is a little fuzzy, so this may or may not be right, but if you look closely, you declared
another_year in a different order between implementations, but used the same line for the inside of the function. Subtraction is an operation that is dependent on the order of numbers involved, so flipping the declaration order of those parameters will affect the output of the function. If the first one works in PyCharm, make sure the line where you declare the
minutes function that you give to Treehouse is exactly the same as the one that's in PyCharm