Deck 7: files and Exceptions

ملء الشاشة (f)
exit full mode
سؤال
Assume 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')
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
What statement can be used to handle some of the run-time errors in a program?

A) exception statement
B) try statement
C) try/except statement
D) exception handler statement
سؤال
What do you call the process of retrieving data from a file?

A) Retrieving data
B) Reading data
C) Input data
D) Get data
سؤال
How many types of files are there?

A) One
B) Two
C) Three
D) four
سؤال
When a piece of data is read from a file, it is copied from the file into the program.
سؤال
Python allows the programmer to work with text and number files.
سؤال
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.
سؤال
Which method could be used to strip specific characters from the end of a string?

A) estrip
B) rstrip
C) strip
D) remove
سؤال
Which of these is associated with a specific file and provides a way for the program to work with that file?

A) filename
B) Extension
C) file object
D) file variable
سؤال
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.
سؤال
Which mode specifier will open a file but will not let you change the file or write to it?

A) 'w'
B) 'r'
C) 'a'
D) 'e'
سؤال
A(n) _____ access file is also known as a direct access file.

A) sequential
B) random
C) numbered
D) text
سؤال
Closing a file disconnects the communication between the file and the program.
سؤال
In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
سؤال
Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist?

A) 'w'
B) 'r'
C) 'a'
D) 'e'
سؤال
What type of file access jumps directly to any piece of data in a file without reading the data that came before it?

A) Sequential
B) Random
C) Number
D) Text
سؤال
Which method could be used to convert a numeric value to a string?

A) str
B) value
C) num
D) chr
سؤال
What happens when a piece of data is written to a file?

A) Data is copied from a variable in RAM to a file.
B) Data is copied from a variable in the program to a file.
C) Data is copied from the program to a file.
D) Data is copied from a file object to a file.
سؤال
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
سؤال
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
سؤال
The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
سؤال
Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.
سؤال
A(n) _______________ file contains data that has not been converted to text.
سؤال
It is possible to create a while loop that determines when the end of a file has been reache
سؤال
A(n) _______________ access file retrieves data from the beginning of the file to the end of the file.
سؤال
The term _______________ file is used to describe a file from which the program gets data.
سؤال
When a program needs to save data for later use, it writes the data in a(n) _______________.
سؤال
A(n) _______________ gives information regarding the line number(s) that caused an exception.
سؤال
If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.
سؤال
Programmers usually refer to the process of _______________ data in a file as "writing data to" the file.
سؤال
A(n) _______________ includes one or more statements that can potentially raise an exception.
سؤال
A(n) _______________ file contains data that has been encoded as text, using a scheme such as ASCII.
سؤال
An exception handler is a piece of code that is written using the try/except statement.
سؤال
The term _______________ file is used to describe a file to which data is written.
سؤال
A filename _______________ is a short sequence of characters that appear at the end of a filename preceded by a period.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/35
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 7: files and Exceptions
1
Assume 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')
D
2
What statement can be used to handle some of the run-time errors in a program?

A) exception statement
B) try statement
C) try/except statement
D) exception handler statement
C
t/false
3
What do you call the process of retrieving data from a file?

A) Retrieving data
B) Reading data
C) Input data
D) Get data
B
4
How many types of files are there?

A) One
B) Two
C) Three
D) four
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
5
When a piece of data is read from a file, it is copied from the file into the program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
6
Python allows the programmer to work with text and number files.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
7
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
8
Which method could be used to strip specific characters from the end of a string?

A) estrip
B) rstrip
C) strip
D) remove
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
9
Which of these is associated with a specific file and provides a way for the program to work with that file?

A) filename
B) Extension
C) file object
D) file variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
10
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which mode specifier will open a file but will not let you change the file or write to it?

A) 'w'
B) 'r'
C) 'a'
D) 'e'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
12
A(n) _____ access file is also known as a direct access file.

A) sequential
B) random
C) numbered
D) text
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
13
Closing a file disconnects the communication between the file and the program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
14
In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist?

A) 'w'
B) 'r'
C) 'a'
D) 'e'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
16
What type of file access jumps directly to any piece of data in a file without reading the data that came before it?

A) Sequential
B) Random
C) Number
D) Text
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which method could be used to convert a numeric value to a string?

A) str
B) value
C) num
D) chr
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
18
What happens when a piece of data is written to a file?

A) Data is copied from a variable in RAM to a file.
B) Data is copied from a variable in the program to a file.
C) Data is copied from the program to a file.
D) Data is copied from a file object to a file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
19
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
20
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
21
The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
22
Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
23
A(n) _______________ file contains data that has not been converted to text.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
24
It is possible to create a while loop that determines when the end of a file has been reache
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
25
A(n) _______________ access file retrieves data from the beginning of the file to the end of the file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
26
The term _______________ file is used to describe a file from which the program gets data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
27
When a program needs to save data for later use, it writes the data in a(n) _______________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
28
A(n) _______________ gives information regarding the line number(s) that caused an exception.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
29
If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
30
Programmers usually refer to the process of _______________ data in a file as "writing data to" the file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
31
A(n) _______________ includes one or more statements that can potentially raise an exception.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
32
A(n) _______________ file contains data that has been encoded as text, using a scheme such as ASCII.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
33
An exception handler is a piece of code that is written using the try/except statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
34
The term _______________ file is used to describe a file to which data is written.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
35
A filename _______________ is a short sequence of characters that appear at the end of a filename preceded by a period.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 35 في هذه المجموعة.