Skip to content

Instantly share code, notes, and snippets.

@ehabkost
Created September 26, 2011 22:47
Show Gist options
  • Save ehabkost/1243630 to your computer and use it in GitHub Desktop.
Save ehabkost/1243630 to your computer and use it in GitHub Desktop.
Challenge: make this code *worse*
try:
datetime.datetime(year+2000 if year < 1000 else year, month, day)
print "%i-%i-%i" % (year+2000 if year < 1000 else year, month, day)
except ValueError:
try:
datetime.datetime(year+2000 if year < 1000 else year, day, month)
print "%i-%i-%i" % (year+2000 if year < 1000 else year, day, month)
except ValueError:
try:
datetime.datetime(month+2000 if month < 1000 else month, day, year)
print "%i-%i-%i" % (month+2000 if month < 1000 else month, day, year)
except ValueError:
try:
datetime.datetime(month+2000 if month < 1000 else month, year, day)
print "%i-%i-%i" % (month+2000 if month < 1000 else month, year, day)
except ValueError:
try:
datetime.datetime(day+2000 if day < 1000 else day, month, year)
print "%i-%i-%i" % (day+2000 if day < 1000 else day, month, year)
except ValueError:
try:
datetime.datetime(day+2000 if day < 1000 else day, year, month)
print "%i-%i-%i" % (day+2000 if day < 1000 else day, year, month)
except ValueError:
print "%s is illegal" % original_input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment