# ----------- # User Instructions # # Modify the valid_year() function to verify # whether the string a user enters is a valid # year. If the passed in parameter 'year' # is not a valid year, return None. # If 'year' is a valid year, then return # the year as a number. Assume a year # is valid if it is a number between 1900 and # 2020. # def valid_year(year): if year.isdigit() and int(year) in range(1900,2021): return int(year) return None print valid_year('1920') # valid_year('0') => None # valid_year('-11') => None # valid_year('1950') => 1950 # valid_year('2000') => 2000
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