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

I have no idea how to do this please help :(

I have been trying to solve this but my way doesn't work

time_machine.py
import datetime

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

# 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)

def time_machine(**kwargs):
    td = datetime.timedelta(**kwargs)
    if 'years' in kwargs:
        tdd = datetime.timedelta(days = 365)
        return starter + (td + (tdd * getattr(other, 'years')
    return starter + td

2 Answers

Pratham Mishra
Pratham Mishra
11,076 Points

def time_machine(time_int, years): if years == 'years': time_int = 365 years = 'days' return starter + datetime.timedelta(*{years : time_int})

Steven Parker
Steven Parker
202,104 Points

The function should take a normal argument, you won't need "kwargs".
Another hint: you should also not need "getattr".