File Handling Practice Problems

21th February 2026 by Tanishq Chavan
Python C C++ Javascript React JS
Python Programming Language

Practice Problems: File Handling

  1. Write to File: Ask the user for a sentence and save it to output.txt.
  2. Read and Count: Read a file and count the number of words in it.
  3. Copy File: Write a program that copies the content of one file to another.
  4. Log System: Append the current time and a "Success" message to a log file.

Example Solution

# Problem 1 Solution
text = input("Enter sentence: ")
with open("output.txt", "w") as f:
    f.write(text)

How did you feel about this post?

๐Ÿ˜ ๐Ÿ™‚ ๐Ÿ˜ ๐Ÿ˜• ๐Ÿ˜ก

Was this helpful?

๐Ÿ‘ ๐Ÿ‘Ž