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 trialTomer Inbar
2,248 PointsPython TZ challenge
Challenge: Create a new timezone for US/Pacific, which is 8 hours behind UTC (UTC-08:00). Then make a new variable named hill_valley that is naive with its tzinfo attribute replaced with the US/Pacific timezone you made.
seems like, I didn't understand what I have been asked. my code is:
import datetime
pacific = datetime.timezone(datetime.timedelta(hours=-8))
hill_valley = datetime.datetime(2015, 10, 21, 4, 29,).replace(tzinfo = pacific)
What am I missing?
[MOD: added ```python markdown formatting -cf]
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsYour code passed for me. There are two ways to create hill_valley:
import datetime
naive = datetime.datetime(2015, 10, 21, 4, 29)
pacific = datetime.timezone(datetime.timedelta(hours=-8))
# apply 'replace' to the "naive" datetime
hill_valley = naive.replace(tzinfo = pacific)
Though, creating a new datetime
object also passes the Task 1:
# apply 'replace' to a new "naive" datetime:
hill_valley = datetime.datetime(2015, 10, 21, 4, 29).replace(tzinfo = pacific)
I did notice a trailing comma after the "29" in your code, but this shouldn't break anything.
Was there some other question?
Peter Rzepka
4,118 Pointsnaive = datetime.datetime(2015, 10, 21, 4, 29)
#define Pacific variable
pacific = datetime.timezone(datetime.timedelta(hours=-8))
#set hill_valley variable tzinfo to your new pacific with same time as naive
hill_valley = datetime.datetime(2015, 10, 21, 4, 29, tzinfo=pacific)
Tomer Inbar
2,248 PointsTomer Inbar
2,248 PointsThanks for the quick response! Have no idea why mine didn't pass.