NEW
Font size
Worksheetsمراجعة درس الملفات
Total questions: 9
Worksheet time: 5mins
What is a file? First step to deal with a file is: Opening the file. What is the format to open a file in Python?
file = open("filename.txt", "mode")
open.file("filename.txt", "mode")
file.open("filename.txt", "mode")
open = file("filename.txt", "mode")
What is the function of the mode "r" when opening a file in Python?
Reading
Writing
Appending
Deleting
What is the function of the mode "w" when opening a file in Python?
Writing (erases previous content, creates new file if not present)
Reading (opens file for reading only)
Appending (adds content to the end of file)
Writing without erasing previous content
What will be printed when you run this code?
42
Error
0
None
What will be written in the file notes.txt?
The file notes.txt will contain the text 'Hello World'.
The file notes.txt will be empty.
The file notes.txt will contain the text 'Goodbye'.
The file notes.txt will contain the text '12345'.
Application: What is the error in the following code? file = open("info.txt", "r") file.write("hello") file.close()
The file is opened in read mode but write operation is performed.
The file is not closed properly.
The file does not exist.
The syntax of open() is incorrect.
After running the code to add a new line to "notes.txt" using the append mode, what happens to the contents of the file?
The first line is erased and only the new line remains.
Only a new line is added; previous contents are preserved.
All lines are duplicated in the file.
The file is overwritten with the new line only.
The function readline() is used to:
Read a line of text from input
Write a line of text to output
Delete a line of text from a file
Append a line of text to a file
What does the function do?
It describes the purpose of the function.
It lists the variables used in the function.
It shows the syntax of the function.
It provides the output of the function.
