QUESTION IMAGE
Question
writing to an non - existing file
the file notes.txt does not exist in the current directly. 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(\hello\
\)
my_notes.write(\some\
\)
my_notes.write(
otes.\
\)
numeric answer
type your response
Step1: Analyze the code
The code opens a file in write mode ('w'). When a file is opened in write mode, if it doesn't exist, it is created. Then, three write operations are performed, each with a string that ends with `
` (new - line character).
Step2: Count the number of new - line characters
The write operations are:
- `my_notes.write("hello
")` (1 sentence)
- `my_notes.write("some
")` (1 sentence)
- `my_notes.write("notes.
")` (1 sentence)
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
3