Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions wk7 - assignment 7.1.py
Original file line number Diff line number Diff line change
@@ -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)