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

I assume, that you have downloaded the above file in the default folder from where your python interpreter or IDE runs.

Then….

Step 1:

# Use “words.txt” as the file name : This will read the file name as string, into memory.
fname = raw_input(“Enter file name: “)

Step 2:

# open downloaded file from default location
fh = open(fname)

Step 3:

# read the content of the file

inp = fh.read()

Step 4:

# Convert all the letters in the content of the file into Upper Case
inp = inp.upper()

Step 5:

# Print the content after removing the double/white and double lines space
print(inp.rstrip())

Advertisements