Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKennedy Malonga
18,790 PointsWrite a function named minutes that takes two datetimes and, using timedelta.total_seconds() to get the number of second
Can't seem to get this right for 2days now
import datetime
def minutes(dt1, dt2):
seconds = datetime.timedelta.total_seconds(dt1 - dt2)
return round(minutes * 60)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Kennedy Malonga! I can tell you've worked on this. In fact, I think you may have overthought this a little bit.
The first line inside the minutes
method is almost perfect. But as the instructions say, you should subtract dt1 from dt2. So instead of (dt1 - dt2)
you will need (dt2 - dt1)
. That will give you the correct number of seconds.
In your final statement, you're using return
to send back minutes
times 60 and rounded. The name minute
is defined but it's the name of the method you're currently in. What I think you meant was that you wanted to round the seconds
. The math here is also not quite right. To get the number of minutes you need to divide the number of seconds
by 60 not multiply minutes by 60. For instance, if I told you that I had been waiting for 210 seconds. That would mean I'd been waiting 3 minutes and 30 seconds. 210 divided by 60 is equal to 3.5.
Instead of round(minutes * 60)
I'm expecting to see round(seconds / 60)
.
Hope this helps!