Python Dates and Times in Python Let's Build a Timed Quiz App Simple Time Machine

Write a function named delorean that takes an integer. Return a datetime that is that many hours ahead from starter.

my output is getting this: Bummer: delorean didn't return the right datetime. Got 2015-10-21 05:29:00.

can't see where I'm getting this wrong everything is changing except the hours :(

Thanks in advanced
import datetime

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

def delorean(ahead):
    return starter.replace(hour=ahead)

1 Answer

Steven Parker
Steven Parker
203,243 Points

You're close, but instead of simply replacing the hour with the argument, you need to add the argument to the current hour:

    return starter.replace(hour=starter.hour+ahead)

Thanks very much Steven Parker it worked, I see the different in code length but not in practicality to me it reads the same. would you be able to explain the difference??

Thanks in advance

no worries I misread your comment thanks appreciate the help