Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!