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 trialJothum Chitewe
7,833 Pointsminutes.py
whats wrong here?
import datetime
def minutes(seconds, microseconds):
return int(datetime.timedelta.total_seconds()/60)
1 Answer
Krishna Pratap Chouhan
15,203 PointsYou are getting two time as input in the function, which you have denoted here as seconds and microseconds. To make it more logical you can name it something like...
import datetime
def minutes(firstTime, secondTime)
#or def minutes(smallerTime, BiggerTime)
When we subtract two datetime objects we get timedelta. so,
import datetime
def minutes(firstTime, secondTime)
timedel = secondTime-firstTime
#timedel object can use a member of datetime.timedelta, called total_seconds() that gives all the seconds in the difference.
seconds = timedel.total_seconds()
#seconds contains all the seconds... rest you already know how to take care.(convert into minutes, round off)
so in your code...
import datetime
def minutes(seconds, microseconds):
return (microseconds-seconds).total_seconds()/60
round-off and its done.