import re
months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
def main():
conversion()
def conversion():
pattern = r'[ /, ]+'
while True:
try:
date = input("Date: ").strip()
month, day, year = re.split(pattern, date)
if month in months:
month = months.index(month) + 1
month = int(month)
day = int(day)
year = int(year)
#print(day)
if day > 31 or month > 12:
pass
else:
print(f"{year}-{month:02}-{day:02}")
break
except ValueError:
pass
main()
import re
months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
def main():
conversion()
def conversion():
pattern = r'[ /, ]+'
while True:
try:
date = input("Date: ").strip()
month, day, year = re.split(pattern, date)
if month in months:
month = months.index(month) + 1
month = int(month)
day = int(day)
year = int(year)
#print(day)
if day > 31 or month > 12:
pass
else:
print(f"{year}-{month:02}-{day:02}")
break
except ValueError:
pass
main()