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 trialAndrew Wilcox
4,374 Pointsminutes.py (stuck by one second???)
I don't understand, says, got the wrong number (the number I need ends on seven and my output ends on 6) I am off just by one unit. just curious what's happening.
Thanks in advanced !
import datetime
def minutes(t1, t2):
duration = t1 - t2
seconds = duration.total_seconds()
minutes = int(seconds / 60)
return minutes
2 Answers
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Andrew,
I copied and pasted your code and got the following error:
Bummer! Got the wrong number of minutes. Expected 1507, got -1506.
So the error in your case is not one unit, it is 3013 units (-1506 vs +1507).
3012 of the units are due to you putting your variables in the wrong order in your subtraction (i.e., 2 - 3
is not the same as 3 - 2
).
As for the remaining one unit, this is because you are getting a whole number by type casting from float to int. This conversion always truncates (rounds down). But the question is asking you to round, which rounds to nearest (which in this case would be rounding up). Hence your difference of 1. There is a specific function for rounding.
Hope that clears everything up for you.
Cheers
Alex
Andrew Wilcox
4,374 PointsI see..!
Thanks a lot!
pierreilyamukuru
9,831 Pointspierreilyamukuru
9,831 PointsHere are two things I can suggest you: 1) Import math and round up with ceil function 2) Remove integers ( int) when using math Ceil Your function looks great and only using ( math.ceil)