months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] monthsShort =[] for i in months: monthsShort.append(i[:3]) monthDict = dict(zip(monthsShort,months)) def valid_day(day): if day and day.isdigit(): if int(day)>=1 and int(day) <=31: return int(day) else: return None def valid_month(month): monthCapped = month.capitalize() if monthCapped[:3] in monthDict: return monthDict[monthCapped[:3]] else: return None def valid_year(year): if year and year.isdigit(): if int(year)>=1900 and int(year) <=2020: return int(year) else: return None print valid_day('30') print valid_year('1924')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question