diff --git a/wk7 - assignment 7.1.py b/wk7 - assignment 7.1.py index 1ec76be..089fe08 100644 --- a/wk7 - assignment 7.1.py +++ b/wk7 - assignment 7.1.py @@ -1,12 +1,17 @@ 7.1 Write a program that prompts for a file name, then opens that file and reads through the file, and print the contents of the file in upper case. Use the file words.txt to produce the output below. You can download the sample data at http://www.pythonlearn.com/code/words.txt -# Use words.txt as the file name -fname = raw_input("Enter file name: ") -fh = open(fname) + #Use words.txt as the file name +fname = input("Enter file name: ") +try : + fh = open(fname) -for line in fh: - line = line.rstrip() -line = line.upper() -print line +except: + print('Cannot open the file ',fname ,'please try again') + quit() + +content = fh.read() +content = content.upper() +content = content.rstrip() +print(content)