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 trialIsaac John
7,516 Pointstime_machine test
import datetime
starter = datetime.datetime(2015, 10, 21, 16, 29)
def time_machine(int, str): #listen for an int and a string
if "years" in str:
return starter + datetime.timedelta(minutes = int * 525949) #increase years
if "days" in str:
return starter + datetime.timedelta(days = int) #increase days
if "hours" in str:
return starter + datetime.timedelta(hours = int) #increase hours
if "minutes"in str:
return starter + datetime.timedelta(minutes = int) #increase minutes
# Remember, you can't set "years" on a timedelta!
I tested this code in Workspaces and just substituted 'return' for 'print' and it works there. but in the test it tells me it returns the wrong answer. I'm assuming that the test inputs an int and a str into my arguments.
1 Answer
Kenneth Love
Treehouse Guest TeacherI'm curious as to why you increased minutes for the 'years'
input instead of increasing days?
Also, 60 minutes * 24 hours * 365 days = 525600 minutes, not 525949.
Isaac John
7,516 PointsIsaac John
7,516 PointsThank you sir...at first I tried days but when it returned incorrect I thought maybe I should try minutes to be more accurate :/ I got the 525949. from google but maybe I copied the wrong thing
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsI think that number may have been an average number of minutes per year accounting for leap years.
1 year = 365.2425 days on average
365.2425 days = 525949.2 minutes