I'm currently running a zoo. The user is asked for a valid date, if the given date is between the inaccessible period for a given animal the animal's name will not be printed, but if it is ouside the period it will. How do I do this if the the date and the period are strings and how do I compare if the date is within the inaccessible period?
Here is the code:
def input_date():
while True:
try:
date = input("Enter the date you want to visit us (DD/MM): ")
pattern_date = ('%d/%m')
date = datetime.strptime(date, pattern_date)
except ValueError:
print("Not a valid date, try again")
continue
else:
break
return date
date = input_date()
class animal:
def __init__(self, species, inaccessible):
self.species = species
self.inaccessible = inaccessible
bear = animal("Bear","01/10 - 31/04")
lion = animal("Lion", "01/11 - 28/02")
penguin = animal("Penguin", "01/05 - 31/08")