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

Python Dates and Times in Python (2014) Dates and Times Wikipedia Links

Is it bad that I couldn't figure this out on my own

I tried doing it myself as the homework before checking this video and I couldn't figure it out. Do you think that I am behind?

Joel Sprunger
Joel Sprunger
5,448 Points

I do not have access to the problem. All I can see is the title and your question. This is a frustrating Treehouse "bug". You ask a question and it is easy to assume that everyone has access to what you are looking at. This gives me a path Python > Dates and Times in Python > Dates and Times > Wikipedia Links, but if I click on the path it doesn't take me to the content you are looking at. Please be more specific.

4 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 38,105 Points

No Aizah it is not bad. If you knew how to do everything you wouldn't need to be taking these courses. Try your best then watch the solution and code along with the solution. If at the end of the course you don't feel you understand it take the course again. You will find that you understand a lot more the next time. Good luck and happy coding.

Joel Sprunger
Joel Sprunger
5,448 Points

No that's fine. Half the time I try to figure it out before watching the video I screw something up. But I think the exercise of trying first really does help you learn, because it shows you where you were thinking incorrectly. When you just start by watching a solution it is easy to follow along and feel like that is the natural logical solution. If you then watch the video and that doesn't make sense, you should probably dig further back into prior videos, or check other resources to clarify.

Sorry for the inconvenience! It is a video titled Wikipedia links

This is the code used in the video

import datetime

answer_format = '%m/%d'
link_format = '%b_%d'
link = '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.")
justlevy
justlevy
6,325 Points

Aizah Sadiq - I think it's OK to not know every solution to a challenge.

For the Wiki Links challenge, I approached it by writing out comments for the steps (using common English, not code). Then I worked on coding each step. It helped me break down the challenge to bite-sized bits.

Also, I did a lot of printing so I could see what was happening.

While not as elegant as Ken's solution, here's my code:

import datetime

def wiki_link():
    user_date = input("Enter date eg. 05 12 (month day):  ")
    format_date = datetime.datetime.strptime(user_date, '%m %d')
    url = format_date.strftime("%b") + "_" + format_date.strftime("%#d")
    print("https://en.wikipedia.org/wiki/" + url)

wiki_link()