I am writing a script to ask user to enter a date. If it is a date format, then return the entry; otherwise, continue. But my code doesn't stop even the user input is valid. Could somebody please share some insight? Thanks!
def date_input(prompt):
while True:
date_text = raw_input(prompt)
try:
datetime.datetime.strptime(date_text, '%Y-%m-%d')
return date_text
except:
print('Invalid input.')
continue