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 trialAva Jones
10,679 PointsThe video did not give me much information about this, can someone please explain this to me
I do not know why this video does not give much info about the challenge
import datetime
def minutes (day1, day2):
timedelta = day2 - day1
1 Answer
Asher Orr
Python Development Techdegree Graduate 9,409 PointsHi Ava!
The directions say:
"Write a function named minutes that takes two datetimes and, using timedelta.total_seconds() to get the number of seconds, returns the number of minutes, rounded, between them. The first will always be older and the second newer. You'll need to subtract the first from the second."
To break it down simply, the challenge wants a function that finds the number of minutes between two datetime objects.
Here's another way to think about it: "I have one datetime object: 3 pm on August 1st. I have another datetime object: 5 pm on August 3rd. How many minutes passed from 3 pm on August 1st to 5 pm on August 3rd?
Your code is doing this:
import datetime
#import datetime module
def minutes (day1, day2):
#define the function "minutes", which takes 2 datetime objects.
timedelta = day2 - day1
#make an object called timedelta, which represents the gap between datetime object 2 and datetime object 1.
Nice work so far.
Now, you need to:
- find the number of seconds in your object "timedelta"
new_object = variable_name.total_seconds()
#in this case, your variable name is "timedelta"
- divide that number by 60 (to get the number of minutes.)
new_object_in_minutes = new_object/60
- return the rounded number of minutes.
return round(new_object_in_minutes)
I hope this helps!