Knowee
Questions
Features
Study Tools

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.py4e.com/code3/words.txt

Question

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.py4e.com/code3/words.txt

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python program that does what you asked for:

# Prompt for a file name
file_name = input("Enter file name: ")

# Open the file
file = open(file_name)

# Read through the file and print the contents in upper case
for line in file:
    print(line.upper())

This program will ask the user to enter a file name, then it will open that file, read through it line by line, and print each line in upper case.

Please note that you need to have the file in the same directory as your python script or provide the full path to the file. Also, the file needs to be readable (i.e., you have the necessary permissions and the file is not locked by another process).

This problem has been solved

Similar Questions

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.

#Write a program to create a text file and print the lines starting with ‘T’ or ‘P’. (Both# uppercase and lowercase)

How do you open a file for reading in Python?Question 6Answera.open(filename, 'a')b.open(filename, 'w')c.open(filename, 'b')d.open(filename, 'r')

Find the output of the following giles text.txt, f is the file object associated with file. (2 Points)Content of test.txt is  Try try but never Cryprint(f.read(4))print(f.read())

Define a function named write_words_start_vowel(filename, names) which takes a filename and a list of words as parameters. The function should write the words that start with a vowel from the list to the file specified by the filename parameter. Each line contains one word only. Note:Remember to close the file.You can assume that the parameter list is not empty.The function needs to handle both uppercase and lowercase letters.The print_contents() function is used for marking purposes. You can assume that it is given in CodeRunner. Do not provide its implementation.For example:Test Resultwrite_words_start_vowel('bdon483.txt', ['life', 'is', 'a', 'long', 'journey', 'with', 'problems', 'to', 'solve'])print_contents('bdon483.txt')

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.