Preparing git repo for final project
This commit is contained in:
41
problems/pset3/outdated/outdated.py
Normal file
41
problems/pset3/outdated/outdated.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import re
|
||||
|
||||
months = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
while True:
|
||||
try:
|
||||
entered_date = input("Date: ").strip()
|
||||
except Exception:
|
||||
continue
|
||||
if re.match(r"\d+/\d+/\d+", entered_date):
|
||||
month, day, year = map(int, entered_date.split('/'))
|
||||
elif re.match(r"\w+ \d{1,2}, \d{4}", entered_date):
|
||||
entered_date = entered_date.replace(",", "")
|
||||
month, day, year = entered_date.split(' ')
|
||||
month = months.index(month) + 1
|
||||
day, year = map(int, (day, year))
|
||||
else:
|
||||
continue
|
||||
if month > 12 or day > 31:
|
||||
continue
|
||||
break
|
||||
print(f"{year:04d}-{month:02d}-{day:02d}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user