Python 3 Chapter 6-11 multiple choice final questions
True
(T/F) A class can be thought of as a blueprint that can be used to create an object.
True
(T/F) A dictionary can include the same value several times but cannot include the same key several times.
False. use key to locate value
(T/F) A dictionary is an object that stores a collection of data. Each element in a dictionary has two parts: a key and a value. You use the value to locate the key.
False
(T/F) All instances of a class share the same values of the data attributes in the class.
True
(T/F) Closing a file disconnects the communication between the file and the program.
True
(T/F) Each subclass has a method named __init__ that overrides the superclass's __init__ method.
False
(T/F) Elements are stored in a dictionary in ascending order, by the keys of the key-value pairs.
True
(T/F) Exception handler is a piece of code that is written using the try/except statement.
False
(T/F) If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode, an alert appears on the screen.
True
(T/F) If the + operator is used on strings, it produces a string that is a combination of the two strings used as its operands.
True
(T/F) If you try to retreive a value from a dictionary using a nonexistent key, a KeyError exception is raised.
False
(T/F) Indexing of a string starts at 1 so the index of the first character is 1, the index of the second charcter is 2, and so forth.
True
(T/F) It is possible to create a while loop that determines when the end of a file has been reached.
True
(T/F) Lists are dynamic data structures such that items may be added to them or removed from them.
True
(T/F) Object -oriented programming allows us to hide the object's data attributes from code that is outside the object.
False
(T/F) The following code will display 'Hello + Python': string1 = 'Hello' string2 = 'Python' string1 += string2 print(string1)
True
(T/F) The index -1 identifies the last element in a list.
False
(T/F) The index of the first element in a list is 1, the index of the second element is 2, and so forth.
True
(T/F) The issubset() method can be used to determine whether set1 is a subset of set2.
True
(T/F) The self parameter is required in every method of class.
True
(T/F) The set remove and discard methods behave differently only when a specified item is not found in the set.
True
(T/F) The sort method rearranges the elements of a list so they are in ascending or descending order.
true
(T/F) To calculate an average of the numeric values in a list (without importing any special modules), the first step is to get the total of values in the list.
False
(T/F) You cannot use a for loop to iterate over the characters in a string.
field
A single piece of data within a record is called a ___________.
getters
Accessor methods are also know as ...
op=open ('authors.txt','w')
Correct way to open a file named authors.txt to write to it.
emp1=Employee()
Create an object named emp1, of the Employee class.
[1,2,3, 1,2,3, 1,2,3,]
Given the following code, what output will be printed? integers = [1, 2, 3] * 3 print(integers)
"1234" (no spaces or commas)
Given the following code, what will be assigned to the variable string1 after the code executes? address = "1234 Main St." string1 = address[ : 4]
Vehicle( the one in())
In the following line of code, what is the name of the base class? class Car(Vehicle):
__init__
Method that is automatically executed when an instance of a class is created in memory.
open the file
Step that creates a connection between a file and a program
read
The process of retrieving data from a file
Does not change
Tuples are great for holding data that ...
object-oriented
Type of programming that contains class definitions
0-11
Valid indexes for the string "North Dakota"
["05", "24", "2013"]
What list will be referenced by the variable dateList after the following code executes? date = '05/24/2013' dateList = date.split('/')
print cities
What will be displayed after the following code executes? (Note: No specific order in dictionaries) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)
[0,2,4]
What will be referenced by the variable number after the following code is executed? number = list(range(0, 5, 2))
No output
What will be the output after the following code is executed and the user enters 75 and -5 for the first two prompts? def main(): try: total = int(input("Enter the total: " )) num = int(input("Enter the number of items: ")) average = total/num except ZeroDivisionError: print("Zero Div error") except ValueError: print("ValueError") main()
"Zero Div Error"
What will be the output after the following code is executed and the user enters 75 and 0 at the first two prompts? def main(): try: total = int(input("Enter the total: " )) num = int(input("Enter the number of items: ")) average = total/num except ZeroDivisionError: print("Zero Div error") except ValueError: print("ValueError") main()
2,4,9,8
What will be the value of the variable list1 after the following code executes? list1 = [2, 4, 6, 8] list1[2] = 9
xyz
What will be the value of the variable string1 after the following code executes? string1 = "xyz" string1.upper()
All letters. b/c
What will display after the following code executes? word = "COMPUTERS" if word.isalpha(): print("All letters") elif word.isdigit(): print("All numbers") elif word.upper(): print("All uppercase") else: print("Something else")
del (not delete)
Which command is used to delete an existing key-value pair from a dictionary?
plus sign
Which operator can be used to concatenate lists?
class Employee:
Wht is the first line needed when creating a class named Employee?
246
Wht will be assigned to the variable numbers after the following code executes? integers = "0123456789" numbers = integers[0:8:2]
Polymorphism
Word that means the ability to define a method in a subclass and then define a method with the same name in a superclass.