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 trialChristine Maxwell
Courses Plus Student 5,103 Pointsminutes.py challenge
Please help me with this challenge
import datetime
def minutes(t1, t2):
t1 = datetime.datetime.now()
t2 = datetime.datetime.now()
deff = datetime.timedelta(t2-t1)
return round(deff.minute)
3 Answers
Kenneth Love
Treehouse Guest TeacherYou don't make a timedelta
with math like that. The act of doing math with two datetime
s will make the timedelta
directly (kinda like how 2 + 2
makes an int directly). So, change your deff
line for that.
And, secondly, timedelta
s don't have a minute
attribute. They have a seconds
attribute, though, so you'll need to turn seconds into minutes before you do the rounding.
Jamison Imhoff
12,460 PointsI had issues with this code challenge as well. After some searching I came across a solution that worked for me:
import datetime
def minutes(datetime1, datetime2):
return int((datetime2-datetime1).seconds/60)
the int() is there because it returns a float without making it into an integer (5.0 instead of 5 minutes)
Hope this helps! If you need help explaining this just let me know!
Kenneth Love
Treehouse Guest TeacherHey, thanks for pointing that it. This challenge shouldn't be solvable with int()
so I've gone and corrected it.
Jamison Imhoff
12,460 PointsSince I used that method to solve it, what exactly should the solution be? I couldn't seem to find another way around it.
Christine Maxwell
Courses Plus Student 5,103 Pointsstick round instead of int in there and works just fine ;)