Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wk7 - assignment 7.1.py #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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)