wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

مراجعة درس الملفات

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

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?

a)

file = open("filename.txt", "mode")

b)

open.file("filename.txt", "mode")

c)

file.open("filename.txt", "mode")

d)

open = file("filename.txt", "mode")

2.

What is the function of the mode "r" when opening a file in Python?

a)

Reading

b)

Writing

c)

Appending

d)

Deleting

3.

What is the function of the mode "w" when opening a file in Python?

a)

Writing (erases previous content, creates new file if not present)

b)

Reading (opens file for reading only)

c)

Appending (adds content to the end of file)

d)

Writing without erasing previous content

4.

What will be printed when you run this code?

a)

42

b)

Error

c)

0

d)

None

5.

What will be written in the file notes.txt?

a)

The file notes.txt will contain the text 'Hello World'.

b)

The file notes.txt will be empty.

c)

The file notes.txt will contain the text 'Goodbye'.

d)

The file notes.txt will contain the text '12345'.

6.

Application: What is the error in the following code? file = open("info.txt", "r") file.write("hello") file.close()

a)

The file is opened in read mode but write operation is performed.

b)

The file is not closed properly.

c)

The file does not exist.

d)

The syntax of open() is incorrect.

7.

After running the code to add a new line to "notes.txt" using the append mode, what happens to the contents of the file?

a)

The first line is erased and only the new line remains.

b)

Only a new line is added; previous contents are preserved.

c)

All lines are duplicated in the file.

d)

The file is overwritten with the new line only.

8.

The function readline() is used to:

a)

Read a line of text from input

b)

Write a line of text to output

c)

Delete a line of text from a file

d)

Append a line of text to a file

9.

What does the function do?

a)

It describes the purpose of the function.

b)

It lists the variables used in the function.

c)

It shows the syntax of the function.

d)

It provides the output of the function.