Deck 6: Files and Exceptions
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
العب
ملء الشاشة (f)
Deck 6: Files and Exceptions
1
Which of the following describes what happens when a piece of data is written to a file?
A) The data is copied from a variable in RAM to a file.
B) The data is copied from a variable in the program to a file.
C) The data is copied from the program to a file.
D) The data is copied from a file object to a file.
A) The data is copied from a variable in RAM to a file.
B) The data is copied from a variable in the program to a file.
C) The data is copied from the program to a file.
D) The data is copied from a file object to a file.
A
2
In Python,there is nothing that can be done if the program tries to access a file to read that does not exist.
False
3
The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y if y = 0.
True
4
Which mode specifier will open a file but not let you change the file or write to it?
A) 'w'
B) 'r'
C) 'a'
D) 'e'
A) 'w'
B) 'r'
C) 'a'
D) 'e'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
A single piece of data within a record is called a
A) variable
B) delimiter
C) field
D) data bit
A) variable
B) delimiter
C) field
D) data bit
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
An exception handler is a piece of code that is written using the try/except statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist?
A) 'w'
B) 'r'
C) 'a'
D) 'e'
A) 'w'
B) 'r'
C) 'a'
D) 'e'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it?
A) sequential
B) random
C) numbered
D) text
A) sequential
B) random
C) numbered
D) text
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
How many types of files are there?
A) one
B) two
C) three
D) more than three
A) one
B) two
C) three
D) more than three
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
Closing a file disconnects the communication between the file and the program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
A(n)__________ access file is also known as a direct access file.
A) sequential
B) random
C) numbered
D) text
A) sequential
B) random
C) numbered
D) text
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
If the last line in a file is not terminated with \n,the readline method will return the line without \n.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which step creates a connection between a file and a program?
A) open the file
B) read the file
C) process the file
D) close the file
A) open the file
B) read the file
C) process the file
D) close the file
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
Python allows the programmer to work with text and number files.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
Strings can be written directly to a file with the write method,but numbers must be converted to strings before they can be written.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
When a piece of data is read from a file,it is copied from the file into the program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the following is associated with a specific file and provides a way for the program to work with that file?
A) the filename
B) the file extension
C) the file object
D) the file variable
A) the filename
B) the file extension
C) the file object
D) the file variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
What is the process of retrieving data from a file called?
A) retrieving data
B) reading data
C) reading input
D) getting data
A) retrieving data
B) reading data
C) reading input
D) getting data
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode,then an alert will appear on the screen.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
It is possible to create a while loop that determines when the end of a file has been reached.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which statement can be used to handle some of the runtime errors in a program?
A) an exception statement
B) a try statement
C) a try/except statement
D) an exception handler statement
A) an exception statement
B) a try statement
C) a try/except statement
D) an exception handler statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts?

A) ERROR: cannot have 0 items
B) ERROR: cannot have 0 items
ERROR: number of items can't be negative
C) ERROR: number of items can't be negative
D) Nothing; there is no print statement to display average. The ValueError will not catch the error.

A) ERROR: cannot have 0 items
B) ERROR: cannot have 0 items
ERROR: number of items can't be negative
C) ERROR: number of items can't be negative
D) Nothing; there is no print statement to display average. The ValueError will not catch the error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
If data is retrieved from a file by a program,this is known by the term __________ file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
When a program needs to save data for later use,it writes the data in a(n)___________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which method could be used to strip specific characters from the end of a string?
A) estrip
B) rstrip
C) strip
D) remove
A) estrip
B) rstrip
C) strip
D) remove
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
Which of the following is the correct way to open a file named users.txt in 'r' mode?
A) infile = open('r', users.txt)
B) infile = read('users.txt', 'r')
C) infile = open('users.txt', 'r')
D) infile = readlines('users.txt', r)
A) infile = open('r', users.txt)
B) infile = read('users.txt', 'r')
C) infile = open('users.txt', 'r')
D) infile = readlines('users.txt', r)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
When data is written to a file,it is described as a(n)__________ file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
A(n)__________ gives information about the line number(s)that caused an exception.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Programmers usually refer to the process of __________ data in a file as writing data to the file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
A(n)___________ block includes one or more statements that can potentially raise an exception.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
A(n)__________ file contains data that has not been converted to text.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
A filename __________ is a short sequence of characters that appear at the end of a filename,preceded by a period.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of the following is the correct way to open a file named users.txt to write to it?
A) outfile = open('w', users.txt)
B) outfile = write('users.txt', 'w')
C) outfile = open('users.txt', 'w')
D) outfile = open('users.txt')
A) outfile = open('w', users.txt)
B) outfile = write('users.txt', 'w')
C) outfile = open('users.txt', 'w')
D) outfile = open('users.txt')
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which method will return an empty string when it has attempted to read beyond the end of a file?
A) read
B) getline
C) input
D) readline
A) read
B) getline
C) input
D) readline
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
What will be the output after the following code is executed and the user enters 75 and 0 at the first two prompts?

A) ERROR: cannot have 0 items
B) ERROR: number of items can't be negative
C) 0
D) Nothing; there is no print statement to display average.

A) ERROR: cannot have 0 items
B) ERROR: number of items can't be negative
C) 0
D) Nothing; there is no print statement to display average.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
Given that the customer file references a file object,and the file was opened using the 'w' mode specifier,how would you write the string 'Mary Smith' to the file?
A) customer file.write('Mary Smith')
B) customer.write('w', 'Mary Smith')
C) customer.input('Mary Smith')
D) customer.write('Mary Smith')
A) customer file.write('Mary Smith')
B) customer.write('w', 'Mary Smith')
C) customer.input('Mary Smith')
D) customer.write('Mary Smith')
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
A(n)___________ file contains data that has been encoded as text,using a scheme such as ASCII.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
A(n)___________ access file retrieves data from the beginning of the file to the end of the file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
Which method could be used to convert a numeric value to a string?
A) str
B) value
C) num
D) chr
A) str
B) value
C) num
D) chr
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
When a file has been opened using the 'r' mode specifier,which method will return the file's contents as a string?
A) write
B) input
C) get
D) read
A) write
B) input
C) get
D) read
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck