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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Zinia Khondoker](https://secure.gravatar.com/avatar/5f7e157498d802feb38843c4f309405f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zinia Khondoker
Python Development Techdegree Graduate 10,451 PointsHarder Time Machine
Is there a way to solve this using the f string? I've excluded the year for now and just curious to see if this works
import datetime
starter = datetime.datetime(2015, 10, 21, 16, 29)
def time_machine(int, "minutes"or "hours" or "days"):
timedelta = datetime.timedelta(f'{"minutes"or "hours" or "days"}={int}')
duration = starter + timedelta
return duration
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsFirst, the declaration needs the second parameter to be a name instead an expression using string literals.
Then, the timedelta needs a keyword and value pair (a "kwarg") instead of a string argument. If you want to get fancy, you can build a dictionary object and then unpack it to create the argument.
When you do make an f-string (in other exercises), you can create a substitution token by surrounding its name with braces. You can also make strings using format() or concatenation.
Gerald Bishop
Python Development Techdegree Graduate 16,897 PointsGerald Bishop
Python Development Techdegree Graduate 16,897 PointsI have also tried this f string approach but still cannot figure out how to make it work. My code gives a TypeError. Please help
Steven Parker
230,688 PointsSteven Parker
230,688 PointsInstead of a string, the timedelta should be given a keyword/value pair or an unpacked dictionary.
Also, don't forget you need to handle "years" as a special case.
And, you won't need to print anything for this challenge.