Deck 8: Text Files
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/58
العب
ملء الشاشة (f)
Deck 8: Text Files
1
Text file is a file containing only printable characters.
False
2
The newline character causes a new line of text to begin when displayed on the screen.
True
3
A text file can be directly displayed on the screen.
True
4
Binary files are structured as separate lines as with text file, but can contain numerical data and therefore cannot be directly displayed on the screen.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following is not true of text files.
A) text files contain printable (displayable) characters
B) text files contain nonprinting characters
C) text files are structured as lines of text
D) text files can be directly displayed on the screen
E) text files cannot contain numeric characters
A) text files contain printable (displayable) characters
B) text files contain nonprinting characters
C) text files are structured as lines of text
D) text files can be directly displayed on the screen
E) text files cannot contain numeric characters
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
6
A ___________________ is a file containing characters structured as lines of text, as well as nonprinting characters such as \n, the newline character.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
7
A ___________________ is a file containing various types of data, such as numerical data, and is not structured as lines of text.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
8
All files must first be opened before they can be read from or written to.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
9
in Python, files are accessed through method calls to an object associated with the open file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
10
To open a file in Python for reading, the openRead function is called and passed the name of the file to open.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
11
When a program opens a file in Python, the file must reside in the same directory (folder) as the program in order to be found.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
12
A file may be closed and then reopened, with reading starting at the beginning of the file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
13
To open a file for writing in Python, 'w' is used to indicate that any existing file of the same name should be written over, and 'a' is used to indicate that the output should be appended to an existing file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
14
It is more likely that an error may occur when opening a file for writing than when opening a file for reading.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
15
Although files should be closed after being opened for either reading or writing. it is especially important to close a file that is open for writing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
16
When reading from a text file, the readline method is used, which returns all the characters on the current line of the file, up to but not including the newline character.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
17
When the end-of-file is reached when reading from a text file, an error is generated.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
18
When writing a line of text to a text file, the write method does not add a newline character to the output string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
19
Fundamental operations of files in include opening a file, _______ a file, __________ a file, and___________ a file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
20
To open a file for reading, the built-in _________ method is used, called with an optional second parameter of ____.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
21
To open a file for writing, the built-in _________ method is used, called with a required second parameter of ____.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
22
When opening a file for reading, an error that may occur is ______________________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
23
When reading a line from a text file, the ________________ method is used.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
24
24. When reading a line from a text file, all the characters up to and including the ___________ character are read and returned.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
25
The ___________ method is used to write to a text file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
26
When writing to or reading from to a file, data is placed in an area of memory called a __________, which make the reading and writing of files more efficient.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
27
Provide Python code that opens a file named names.txt, in which each line of the file contains a friends name in the form firstname lastname, and displays each of the names on the screen, one per screen line.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
28
Provide Python code that prompts the user for the file name of the form filename.txt of a text file, opens the file, and displays each of the names on the screen, one per screen line.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
29
Provide Python code that prompts the user for the file name of the form filename.txt of a text file, opens the file, and writes the contents of the file to a new file name filename-2.txt.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
30
Any of the sequence methods of Python may be applied to strings.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
31
Strings are immutable in Python, and therefore cannot be altered.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
32
Any string method involving the modification of a string returns a new string containing the modification, with the original string the method is called on unchanged.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
33
Collectively, the operations performed on strings is called _______________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
34
The ________ string method in Python can be used to determine if a string contains only letters, whereas the __________ method can be used determine is a string contains only digits.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
35
The ________ and __________ string methods in Python can be used to determine if a string contains only lowercase or uppercase characters, whereas the __________ and ___________ methods can be used to convert a string to all lowercase or all uppercase characters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
36
Give Python code that displays the longer of two names, name1 and name2.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
37
Give Python code that display "Valid SSN" if the string assigned to variable SSN is a valid social security number, and displays "Invalid SSN" otherwise. A social security number is valid if it contains exactly nine digits, and no other characters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
38
Give Python code that removes any occurrences of dashes from a given social security number that variable SSN is assigned to, and updates SSN to contain the dash-removed result.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
39
Give Python code that, for any state of the U.S. assigned to variable state_name, displays the name ensuring that the first letter is displayed capitalized.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
40
Give Python code that, for a first name and last name assigned to variable full_name with the first and last name separated by a single space (e.g., Alice Morgan), displays the first name only.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
41
Give Python code that for a first name and last name assigned to variable full_name with the first and last name separated by a single space (e.g., Alice Morgan), assigns the first name to variable first_name and the last name to variable last_name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
42
An exception is an object that is raised when an unexpected situation has occurred.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
43
All raised exceptions should be able to be caught and handled to keep a program executing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
44
Python contains a predefined set of exceptions called standard exceptions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
45
Exceptions that are thrown by a given function must be caught by the function to gracefully handle errors.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
46
Exceptions must be caught and handled by the calling code of the function throwing the exceptions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
47
If an exception is thrown all the back to the main module and not handled there, the program terminates.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
48
The section of code making a call to any function that raises an exception must be contained in a try suite (block).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
49
An exception handler is the section of code that is executed when a particular exception type is caught.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
50
Which of the following is not a standard exception in Python?
A) ImportError
B) IndexError
C) AssignmentError
D) TypeError
E) ValueError
A) ImportError
B) IndexError
C) AssignmentError
D) TypeError
E) ValueError
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
51
An exception is a value (object) that is __________ when an exceptional situation occurs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
52
The predefined exceptions in Python are called the ____________ exceptions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
53
The expression 'Hello' + 10 would raise a _________________ exception on Python.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
54
The expression int('10A') would raise a ________________ exception on Python.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
55
55. The section of code that is to be executed when a particular exception has been caught is called an _____________________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
56
Give section of code that prompts the user for an integer value, and displays the number entered if no exception is raised, otherwise catches the exception when a non-numeric character is entered, displaying the message "non-digit found in input."
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
57
Write a function called getNum(start, end) that is passed the starting and ending values of a range of integers, prompts the user to enter an integer in the specified range, and returns the integer entered. The function should throw a ValueError exception if the entered number is not within the required range.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
58
Write a function called getYearOfBirth that prompts the user to enter their year of birth as a four-digit number, and returns the year entered. The function should throw a ValueError exception if the entered number is not within the range 1900 to the present year. Write a program that call this function, and keeps calling it until a valid year has been entered.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck