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

wiki.py modified for a list of dates

import datetime

answer_format = '%m/%d'
link_format = '%b_%d'
link = 'https://en.wikipedia.org/wiki/{}'

answer = []

while True:
    answer.append(
        input("""
            What date would you like? Please use the MM/DD format.
            Enter 'quit' to quit.
            """))
    if answer[-1].upper() == 'QUIT':
        answer = answer[:-1]
        break

for ans in answer:
    date = datetime.datetime.strptime(ans, answer_format)
    output = link.format(date.strftime(link_format))
    print(output)
Adam Sullivan
Adam Sullivan
9,386 Points

The objective Kenneth proposed was to modify the wiki.py script so that it can accept a list of dates and also return a list of wiki links. After I indented the for loop I was able to get back a wiki link with the date I entered. The problems I'm having and am hoping someone can solve are:

-How do I get the links that are returned to be in a list form, separated by commas rather than appearing on the next line?

-Also, this doesn't seem to allow for a list of multiple dates to be entered and then returned at the same time. When I try doing so, I keep getting a ValueError saying unconverted data remains and showing the dates that were entered after the first one. It seems like the input part of this is necessary for being able to use 'quit'. Is it possible to store the inputted values as separate items within the 'answer' variable so that the for loop works smoothly?

Can anyone please give advice or help answer these questions? Thank you!