QUESTION IMAGE
Question
writing to an existing file
unanswered • • 46 seconds left
the file notes.txt contains the following text:
hello
some
notes.
how many sentences (text ended by a new line) would be in the file notes.txt after we run the following code?
my_notes = open(notes.txt, w)
my_notes.write(\some\
\)
my_notes.write(\more\
\)
my_notes.write(
otes\
\)
my_notes.write(\added\
\)
numeric answer
type your response
Step1: Understand file opening mode
When opening a file in 'w' mode (write mode), it truncates the existing file. So the original content (`hello
some
notes.`) is erased.
Step2: Analyze the written content
The code writes `"some
more
notes
added
". Each
` represents a new - line. Counting the number of lines:
The text written is some, more, notes, added. The number of lines (sentences as per the definition in the problem) is calculated by counting the non - newline parts separated by `
`. There are 4 non - newline parts.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
4