I have been having trouble making this program loop... i want i to ask for the input if they give a string or a date in the wrong format...this is my code for it and i don't know why its not working. every time i run it and input a string, the first time it will say "Oops! That was not a valid date. Try again..." if the user inputs the wrong input again it crashes
THIS IS MY CODE.
while 1 == 1:
try:
birthday = raw_input("Enter your Birth date in MM/DD/YYYY format: ")
birth_date = datetime.strptime(birthday, '%m/%d/%Y')
except ValueError:
print "Oops! That was not a valid date. Try again..."
birthday = raw_input("Enter your Birth date in MM/DD/YYYY format: ")
birth_date = datetime.strptime(birthday, '%m/%d/%Y')
if (((datetime.today() - birth_date).days)/365.2425) > 110:
print "Sorry You are older than 110 year i cannot do that math."
elif ((datetime.today() - birth_date).days) < 0:
print "Sorry you entered a date in the furture."
elif ((datetime.today() - birth_date).days) == 0:
print "OMG You were just born, tomorrow you will be one day old."
else:
print "Age: %d days " % ((datetime.today() - birth_date).days)
THIS IS THE ERROR IT SHOWS:
birth_date = datetime.strptime(birthday, '%m/%d/%Y')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'ASFA' does not match format '%m/%d/%Y'
logout