Knowee
Questions
Features
Study Tools

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.

Question

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.

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

Solution

Here is a Python program that accomplishes the task:

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

# Open the file
with open(file_name, 'r') as file:
    # Read through the file
    for line in file:
        # Print the contents of the file in upper case
        print(line.upper())

This program first prompts the user to enter a file name. It then opens the file in read mode ('r'). It reads through the file line by line, and for each line, it prints the line in upper case.

To use the file words.txt, you would enter "words.txt" (without the quotes) when prompted for a file name.

This problem has been solved

Similar Questions

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

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

Print the number of lines, words, and characters in a file.Write a program to print the number of lines, words, and characters in a file.Note: Take the input file name from the user.Sample Test CasesTest Case 1:Expected Output:Enter·file·name:·InputData1.txtLine·count·=·7Word·count·=·51Char·count·=·306

Write a program that carries out the following tasks:Open a file with the name hello.txt.Store the message “Hello, World!” in the file.Close the file.Open the same file again.Read the message into a string variable and print it.

File Handling:●Write a program that reads a text file and prints the number of words in it

1/3

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.