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

Chang Hyeon Lee
Chang Hyeon Lee
2,008 Points

I need some help

can you give me a hint about this? Thank you!

time_machine.py
import datetime

starter = datetime.datetime(2015, 10, 21, 16, 29)

def time_machine(integer, string):
    if string == 'hours' :
        tdelta = datetime.timedelta(hours = integer)
    elif string == 'days' :
        tdelta = datetime.timedelta(days = integer)
    elif string == 'years' :
        tdelta = datetime.timdelta(years = integer*365)
    elif string == 'minutes' :
        tdelta = datetime.timedelta(minutes = integer)

    new_time = starter + tdelta
    return new_time


# Remember, you can't set "years" on a timedelta!
# Consider a year to be 365 days.

## Example
# time_machine(5, "minutes") => datetime(2015, 10, 21, 16, 34)

1 Answer

Stuart Wright
Stuart Wright
41,119 Points

You have two errors, both in this code segment:

    elif string == 'years' :
        tdelta = datetime.timdelta(years = integer*365)

The first one a simple typo - 'timdelta'.

The second one, you are very close but timedelta has no years attribute - remember the reason why you did the * 365 multiplication and choose a more appropriate attribute to assign the value of integer * 365 to.