Question

Help me write a python code. Write a program that asks the user for the name...

Help me write a python code. Write a program that asks the user for the name of a text file, then reads each line of the text file and prints it on the screen, making every other line "title case." For example, suppose the following text is saved in my_file.txt:

While I nodded, nearly napping

Suddenly there came a tapping

As of someone gently rapping,

Rapping at my chamber door.

When run, the program looks like this:

Enter filename:

While I nodded, nearly napping

Suddenly There Came A Tapping

As of someone gently rapping,

Rapping At My Chamber Door.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

file = open("my_file.txt", "r")
for line in file:
line.title()
file.close()

Output:

file open(my file.txt, r or Tine in file : line.title( file.close()

Add a comment
Know the answer?
Add Answer to:
Help me write a python code. Write a program that asks the user for the name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • IN PYTHON Write a program that asks the user for the name of a file ....

    IN PYTHON Write a program that asks the user for the name of a file . The program should display the contents of any file with each line preceded with a line number followed by a colon. The line number should start at 1

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Python: Implement a function myIndex() that takes as input a text file and a list of...

    Python: Implement a function myIndex() that takes as input a text file and a list of words. Search the file and print the word along with the line numbers that word appears in the text as follows: >>> myIndex('raven.txt', ['raven', 'mortal', 'dying', 'ghost', 'ghastly', 'evil', 'demon']) raven     44, 53, 55, 64, 78, 97, 104, 111, 118, 120 mortal    30 dying     9 ghost     9 ghastly   82 evil      99, 106 demon     122 reven.txt: Once upon a midnight dreary, while I pondered weak...

  • Write a program that reads in a text file, infile.txt, and prints out all the lines...

    Write a program that reads in a text file, infile.txt, and prints out all the lines in the file to the screen until it encounters a line with fewer than 4 characters. Once it finds a short line (one with fewer than 4 characters), the program stops. For your testing you should create a file named infile.txt. Only upload your Python program, I will create my own infile.txt. Please use a while-loop BUT do not use break, Exit or Quit...

  • In Python, write a program that reads a text file that is provided by the user...

    In Python, write a program that reads a text file that is provided by the user - ensure that the file exists before processing it! The file might be in a different directory, so be sure to test you logic - the user will provide the absolute path to the file if it is not in the same directory as the Python script! You should then ask the user for what string to search for in the file. Your program...

  • Write a program that allows the user to navigate the lines of text in a file....

    Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...

  • Write a program in java that asks a user for a file name and prints the...

    Write a program in java that asks a user for a file name and prints the number of characters, words (separated by whitespace), and lines in that file. Then, it replaces each line of the file with its reverse. For example, if the file contains the following lines (Test1.txt): This is a test Hi there Output on the console: Number of characters: 22 Number of words: 6 Number of lines: 2 Data written to the file (Test1.txt): tset a si...

  • Python 3: Write a program in python that asks the user to enter a number that...

    Python 3: Write a program in python that asks the user to enter a number that contains 4 digits, i.e. in the range [1000-9999]. Your program MUST take it as a number integer. Print each digit on a separate line.

  • "Write a python program that gets a line of text from the user and prints the...

    "Write a python program that gets a line of text from the user and prints the line 5 times, with line numbers 1 to 5 attached in the beginning of each line." I do not know how to add the numbers to each line. What should I do?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT