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 trialLeah Miller
16,291 PointsWiki Links Extra Credit: I did it! Please give any feedback/suggestions on ways to make it better!
Thanks for checking it out! Kenneth Love
1 Answer
frankgenova
Python Web Development Techdegree Student 15,616 Points"""Enter a date and return it as a wiki link."""
import datetime
answer_format = '%m/%d'
link_format = '%b_%d'
link = 'https://en.wikipedia.org/wiki/{}'
links = []
while True:
answer = input("What dates would you like? Please use the MM/DD format. Enter 'quit' to quit. Enter 'print' to see list of links. ")
if answer.upper() == 'QUIT':
break
elif answer.upper() == 'PRINT':
print("\nLinks: ")
for link in links:
print(" " + link)
else:
try:
date = datetime.datetime.strptime(answer, answer_format)
output = link.format(date.strftime(link_format))
links.append(output)
except ValueError:
print("That's not a valid date. Please try again.")
frankgenova
Python Web Development Techdegree Student 15,616 Pointsfrankgenova
Python Web Development Techdegree Student 15,616 PointsHere are some suggestions:
You are asking the user to input a date in format MM/DD and you also give them two other options to input. The other options are 'quit' and 'print'. You correctly check to see if the user entered 'quit' at the top of the while loop and exit appropriately. However, you are not then checking if the user entered 'print'. Instead, you are always printing outside the while loop. Run your code and test the following inputs: 'quit', mm/dd, 'print'. Think of 'print' as an elif option and this should work.
Spoiler Alert > I will also post my version of your code.