BUS 392 Exam 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Base classes are also called a. superclasses b. derived classes c. subclasses d. class instances

A

In a UML diagram, what does the open arrowhead point to? a. the superclass b. the subclass c. the object d. a method

A

In the following line of code, what is the name of the subclass? class Rose(Flower): a. Rose b. Flower c. Rose(Flower) d. None of these

A

Mutator methods are also known as a. setters b. getters c. instances d. attributes

A

Of the two classes, Cherry and Flavor, which would most likely be the subclass? a. Cherry b. Flavor c. either one d. neither; these are inappropriate class or subclass names

A

The procedures that an object performs are called a. methods b. actions c. modules d. instances

A

What are the valid indexes for the string 'New York'? a. 0 through 7 b. 0 through 8 c. -1 through -8 d. -1 through 6

A

What does the acronym UML stand for? a. Unified Modeling Language b. United Modeling Language c. Unified Model Language d. Union of Modeling Languages

A

What gives a program the ability to call the correct method depending on the type of object that is used to call it? a. Polymorphism b. Inheritance c. Encapsulation d. Methods

A

What is the process used to convert an object to a stream of bytes that can be saved in a file? a. pickling b. streaming c. writing d. dumping

A

What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method? a. accessor b. mutator c. setter d. class

A

What will be assigned to the string variable pattern after the following code executes? i = 3 pattern = 'z' * (5 * i) a. 'zzzzzzzzzzzzzzz' b. 'zzzzz' c. 'z * 15' d. Nothing; this code is invalid

A

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:] a. ' Country Ln.' b. '1357' c. 'Coun' d. '57 C'

A

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 total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') main() 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

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10 a. [1, 2, 3, 10] b. [1, 2, 10, 4] c. [1, 10, 10, 10] d. Nothing; this code is invalid

A

What will be the value of the variable list2 after the following code executes? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. Nothing; this code is invalid

A

What will display after the following code executes? password = 'ILOVEPYTHON' if password.isalpha(): print('Invalid, must contain one number.') elif password.isdigit(): print('Invalid, must have one non-numeric character.') elif password.isupper(): print('Invalid, cannot be all uppercase characters.') else: print('Your password is secure!') a. Invalid, must contain one number. b. Invalid, must have one non-numeric character. c. Invalid, must contain one number. Invalid, cannot be all uppercase characters. d. Your password is secure!

A

When there are several classes that have many common data attributes, it is better to write a(n) __________ to hold all the general data. a. superclass b. subclass c. object d. method

A

Which attributes belong to a specific instance of a class? a. instance b. self c. object d. data

A

Which method could be used to convert a numeric value to a string? a. str b. value c. num d. chr

A

Which method would you use to determine whether a certain substring is the suffix of a string? a. endswith(substring) b. find(substring) c. replace(string, substring) d. startswith(substring)

A

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

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

Which of the following would you use if an element is to be removed from a specific index? a. a del statement b. a remove method c. an index method d. a slice method

A

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

Which would you use to delete an existing key-value pair from a dictionary? a. del b. remove c. delete d. unpair

A

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)? a. { 1 ; 'January', 2 ; 'February', ... 12 ; 'December'} b. { 1 : 'January', 2 : 'February', ... 12 : 'December' } c. [ '1' : 'January', '2' : 'February', ... '12' : 'December' ] d. { 1, 2,... 12 : 'January', 'February',... 'December' }

B

What is the first negative index in a list? a. 0 b. -1 c. -0 d. the size of the list minus 1

B

What is the first negative index in a string? a. 0 b. -1 c. -0 d. the size of the string minus one

B

What is the process of retrieving data from a file called? a. retrieving data b. reading data c. reading input d. getting data

B

What is the return value of the string method lstrip()? a. the string with all whitespaces removed b. the string with all leading whitespaces removed c. the string with all leading tabs removed d. the string with all leading spaces removed

B

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = 5556666' a. {'John' : '5555555', 'Julie' : '5557777'} b. {'John' : '5556666', 'Julie' : '5557777'} c. {'John' : '5556666'} d. This code is invalid.

B

What list will be referenced by the variable list_strip after the following code executes? my_string = '03/07/2018' list_strip = my_string.split('/') a. ['3', '7', '2018'] b. ['03', '07', '2018'] c. ['3', '/', '7', '/', '2018'] d. ['03', '/', '07', '/', '2018']

B

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4] a. '7' b. '1357' c. 5 d. '7 Country Ln.'

B

What will be the value of the variable string after the following code executes? string = 'abcd' string.upper() a. 'abcd' b. 'ABCD' c. 'Abcd' d. Nothing; this code is invalid

B

Which is the first line needed when creating a class named Worker? a. def__init__(self): b. class Worker: c. import random d. def worker_pay(self):

B

Which method can be used to convert a list to a tuple? a. append b. tuple c. insert d. list

B

Which method could be used to strip specific characters from the end of a string? a. estrip b. rstrip c. strip d. remove

B

Which method or operator can be used to concatenate lists? a. * b. + c. % d. concat

B

Which method would you use to determine whether a certain substring is present in a string? a. endswith(substring) b. find(substring) c. replace(string, substring) d. startswith(substring)

B

Which method would you use to get all the elements in a dictionary returned as a list of tuples? a. list b. items c. pop d. keys

B

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'

B

Which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate on the data attributes? a. a class b. an object c. an instance d. a module

B

Which section in the UML holds the list of the class's data attributes? a. first section b. second section c. third section d. fourth section

B

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

B

A single piece of data within a record is called a a. variable b. delimiter c. field d. data bit

C

Combining data and code in a single object is known as a. modularity b. instantiation c. encapsulation d. objectification

C

If the start index is __________ the end index, the slicing expression will return an empty string. a. equal to b. less than c. greater than d. less than or equal to

C

In object-oriented programming, one of first tasks of the programmer is to a. list the nouns in the problem b. list the methods that are needed c. identify the classes needed d. identify the objects needed

C

In order to create a graph in Python, you need to include a. import matplotlib b. import pyplot c. import matplotlib.pyplot d. import matplotlib import pyplot

C

What does the get method do if the specified key is not found in the dictionary? a. It throws an exception. b. It does nothing. c. It returns a default value. d. You cannot use the get method to specify a key.

C

What is an advantage of using a tuple rather than a list? a. Tuples are not limited in size. b. Tuples can include any data as an element. c. Processing a tuple is faster than processing a list. d. There is never an advantage to using a tuple.

C

What is the relationship called in which one object is a specialized version of another object? a. parent-child b. node-to-node c. is a d. class-subclass

C

What is the special name given to the method that returns a string containing an object's state? a. __state__ b. __obj__ c. __str__ d. __init__

C

What type of programming contains class definitions? a. procedural b. top-down c. object-oriented d. modular

C

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:] a. '135' b. '753' c. 'Ln.' d. 'y Ln'

C

What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2] a. '0123456789' b. '24682468' c. '02468' d. '02020202020202020202'

C

What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print(mystr) a. yes + no * 2 b. yes + no yes + no c. yesnono d. yesnoyesno

C

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities) a. {'FL': 'Tallahassee'} b. KeyError c. {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'} d. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

C

What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3 a. [1, 2] * 3 b. [3, 6] c. [1, 2, 1, 2, 1, 2] d. [1, 2], [1, 2], [1, 2]

C

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!' a. 'Hello' b. ' world!' c. 'Hello world!' d. Nothing; this code is invalid

C

When an object is passed as an argument, __________ is passed into the parameter variable. a. a copy of the object b. a reference to the object's state c. a reference to the object d. Objects cannot be passed as arguments.

C

When working with multiple sets of data, one would typically use a(n) a. list b. tuple c. nested list d. sequence

C

Which method can be used to add a group of elements to a set? a. add b. addgroup c. update d. addset

C

Which method can be used to place an item at a specific index in a list? a. append b. index c. insert d. add

C

Which method is automatically called when you pass an object as an argument to the print function? a. __state__ b. __obj__ c. __str__ d. __init__

C

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary? a. list b. items c. pop d. popitem

C

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

C

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)

C

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')

C

Which of the following will create an object, worker_joey, of the Worker class? a. def__init__(worker_joey): b. class worker_joey: c. worker_joey = Worker() d. worker_joey.Worker

C

Which section in the UML holds the list of the class's methods? a. first section b. second section c. third section d. fourth section

C

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

C

Which would you use to get the number of elements in a dictionary? a. size b. length c. len d. sizeof

C

__________ has the ability to define a method in a subclass and then define a method with the same name in a superclass. a. Inheritance b. Encapsulation c. Polymorphism d. the 'is a' relationship

C

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')

D

In a dictionary, you use a(n) __________ to locate a specific value. a. datum b. element c. item d. key

D

The primary difference between a tuple and a list is that a. you don't use commas to separate elements in a tuple b. a tuple can only include string elements c. a tuple cannot include lists as elements d. once a tuple is created, it cannot be changed

D

What does a subclass inherit from a superclass? a. instances and attributes b. objects and methods c. methods and instances d. attributes and methods

D

What is the number of the first index in a dictionary? a. 0 b. 1 c. the size of the dictionary minus one d. Dictionaries are not indexed by number.

D

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities) a. {'CA': 'Sacramento'} b. ['CA': 'Sacramento'] c. {'NY': 'Albany', 'GA': 'Atlanta'} d. {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

D

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities) a. {'FL': 'Tallahassee'} b. KeyError c. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'} d. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

D

What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') main() 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.

D

What will be the output after the following code is executed? import matplotlib.pyplot as plt def main(): x_crd = [0, 1 , 2, 3, 4, 5] y_crd = [2, 4, 5, 2] plt.plot(x_crd, y_crd) main() a. It will display a simple line graph. b. It will display a simple bar graph. c. Nothing; plt is not a Python method. d. Nothing; the number of x-coordinates do not match the number of y-coordinates.

D

What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] a. False b. -1 c. 0 d. KeyError

D

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

D

Which list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2) a. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] b. [1, 3, 5, 7, 9] c. [2, 4, 6, 8] d. [0, 2, 4, 6, 8]

D

Which method can be used to convert a tuple to a list? a. append b. tuple c. insert d. list

D

Which method is automatically executed when an instance of a class is created in memory? a. __state__ b. __obj__ c. __str__ d. __init__

D

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

D

Which of the following does not apply to sets? a. The stored elements can be of different data types. b. All the elements must be unique; you cannot have two elements with the same value. c. The elements are unordered. d. The elements are in pairs.

D

__________ allows a new class to inherit members of the class it extends. a. Encapsulation b. Attributes c. Methods d. Inheritance

D

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the __________ operator. a. included b. in c. isnotin d. isin

B

In the following line of code, what is the name of the base class? class Python(Course): a. Python b. Course c. Python(Course) d. None of these

B

What are the data items in a list called? a. data b. elements c. items d. values

B

A(n) __________ access file is also known as a direct access file. a. sequential b. random c. numbered d. text

B

Accessor methods are also known as a. setters b. getters c. instances d. attributes

B

Given the following line of code, in a UML diagram, what would the open arrowhead point to? class Celery(Vegetable): a. Celery b. Vegetable c. class d. Celery(Vegetable)

B

How many types of files are there? a. one b. two c. three d. more than trhee

B

In an inheritance relationship, what is a specialized class called? a. a superclass b. a subclass c. an object d. an instance

B


संबंधित स्टडी सेट्स

Corporal's Course (Tactical Planning)

View Set

Texas Pol: Quiz #4 (CHC Chapter 5)

View Set

PrepU Chapter 50: Biliary Disorders

View Set

IDFX Practice test (125 Questions)

View Set

FLUID AND ELECTROLYTES UNIT 4 semester 2

View Set

Introduction to romanticism 100%

View Set

Sadler Vocabulary Workshop Choosing the Right Word

View Set