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
Elizabeth McInerney
3,175 Pointswiki.py
I tried to replicate Kenneth's code from the wiki video in the Date/Time module, and I get an error saying that link is not defined.
# Make a script that accepts a month/day date in whatever format you want that returns a link to
# wikipedia for that date.
# Be sure to tell the user how to format their data for you.
import datetime
answer_format = '%m/%d'
link_format = '%b_%d'
lin = 'https://en.wikipedia.org/wiki/{}'
while True:
answer = input("What date would you like? Please use the MM/DD format. Enter 'quit' to quit.")
if answer.upper() == 'QUIT':
break
try:
date = datetime.datetime.strptime(answer, answer_format)
output = link.format(date.strftime(link_format))
print(output)
except ValueError:
print("That's not a valid date. Please try again.")
2 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsI don't see where you're not using the variable lin in your code loop. Do you mean to use:
output = lin.format(date.strftime(link_format))
Elizabeth McInerney
3,175 PointsI see it, I meant to use link for the web address. That's a typo. I have to stop looking at just the line that is flagged when an error pops up. Often the error starts somewhere else. I will fix it and try again.
Elizabeth McInerney
3,175 PointsThat worked. Thanks!
Chris Freeman
Treehouse Moderator 68,468 PointsChris Freeman
Treehouse Moderator 68,468 PointsPerhaps you meant to name it
linkinstead oflin.