""" Adam Brandeis Homework 2.15 NOTE: PLEASE REMOVE ANY UNNEEDED AND TEST CODE, AND USE COMMENTS ONLY WHEN NECESSARY TO CLARIFY YOUR CODE. Use raw_input() to take user input - a 4-digit year. Test the input to see that it is all numbers -- if it is not all numbers, print an error message and exit() (hint: use the isdigit() method with not to test the input). Loop through the Fama-French_data.txt file, print each line that begins with this year. Make sure there are no blank lines between printed lines. After the file lines are printed, report the number of lines that were printed. """ #!/usr/bin/python data = 'FamaFrench_data.txt' year = raw_input(' Please enter a 4 digit year, e.g. 1994 : ') print year.isdigit() if not year.isdigit(): print ' You did not enter a valid year or number! ' else: print ' You entered ' + year for line in open(data): print line
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