File Handling Practice Problems
21th February 2026 by Tanishq Chavan
Python
C
C++
Javascript
React JS
Practice Problems: File Handling
- Write to File: Ask the user for a sentence and save it to
output.txt. - Read and Count: Read a file and count the number of words in it.
- Copy File: Write a program that copies the content of one file to another.
- 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)