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 trial

Python Dates and Times in Python (2014) Let's Build a Timed Quiz App Harder Time Machine

Isaac John
Isaac John
7,516 Points

time_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.

http://teamtreehouse.com/library/dates-and-times-in-python/lets-build-a-math-quiz-app/harder-time-machine

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I'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
Isaac John
7,516 Points

Thank 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

I 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