Chapter 5,7,8,9, and 10 review questions and T/F

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

A hierarchy chart does not show the steps that are taken inside a function.

true

Tuples in Python are immutable.

true

Which of the following statements creates a tuple? a. values = [1, 2, 3, 4] b. values = {1, 2, 3, 4} c. values = (1) d. values = (1,)

values = (1,)

The method used to write an entire list to a file is known as a. writelines b. writeline c. writelists d. writelist

writelines

You can use _________ to create an empty dictionary. a. {} b. () c. [] d. empty()

{}

This string method returns a copy of the string with all leading whitespace characters removed. a. lstrip b. rstrip c. remove d. strip_leading

lstrip

This built-in function returns the highest value in a list. a. minimumOf() b. minimum() c. min() d. least()

max()

Assume the following statement appears in a program: mylist = [ ] Which of the following statements would you use to add the string 'Labrador' to the list at index 0? a. mylist[0] = 'Labrador' b. mylist.insert(0, 'Labrador') c. mylist.append('Labrador') d. mylist.insert('Labrador', 0)

mylist.insert(0, 'Labrador')

A(n) __________ is a special variable that receives a piece of data when a function is called. a. argument b. parameter c. header d. packet

parameter

The _________ method returns the value associated with a specified key and removes that key-value pair from the dictionary. a. pop() b. random() c. popitem() d. rand_pop()

pop()

The ______________ programming practice is centered on creating functions that are separate from the data that they work on. a. modular b. procedural c. functional d. object-oriented

procedural

This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0). a. random b. randint c. random_integer d. uniform

randint

This file object method returns a list containing the file's contents. a. to_list b. getlist c. readline d. readlines

readlines

This set method removes an element and raises an exception if the element is not found. a. remove b. discard c. delete d. erase

remove

This statement causes a function to end and sends a value back to the part of the pro- gram that called the function. a. end b. send c. exit d. return

return

A(n) __________ is the part of a program in which a variable may be accessed. a. declaration space b. area of visibility c. scope d. mode

scope

This value initializes the formula that generates random numbers. a. dummy value b. random value c. seed value d. new value

seed value

This string method returns a copy of the string with all leading and trailing whitespace characters removed. a. clean b. strip c. remove_whitespace d. rstrip

strip

This string method returns true if a string contains only alphabetic characters and is at least one character in length. a. the isalpha method b. the alpha method c. the alphabetic method d. the isletters method

the isalpha method

Which of the following is not a property of tuples? a. Tuples are immutable data structures b. Tuples do not support functions like len, min, max c. Tuples can be accessed just like lists d. Processing tuples is faster than lists

Tuples do not support functions like len, min, max

You can add one element to a set with this method. a. append b. add c. update d. merge

add

This type of function returns either True or False. a. Binary b. true_false c. Boolean d. logical

boolean

In Python, lists are a. mutable data structures b. static data structures c. dynamic data structures d. Both a and c

both a and c

A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is __________. a. code reuse b. divide and conquer c. debugging d. facilitation of teamwork

code reuse

The first line of a function definition is known as the __________. a. body b. introduction c. initialization d. header

header

This function returns the length of a string. a. length b. size c. len d. lengthof

len

20. This is not a function of math module. a. hypot (x, y) b. radians (x) c. sin (x) d. len (x)

len(x)

This is a prewritten function that is built into a programming language. a. standard function b. library function c. custom function d. cafeteria function

library function

A __________ is a variable that is created inside a function. a. global variable b. local variable c. hidden variable d. none of the above; you cannot create a variable inside a function

local variable

When the * operator's left operand is a list and its right operand is an integer, the opera- tor becomes this. a. The multiplication operator b. The repetition operator c. The initialization operator d. Nothing—the operator does not support those types of operands.

The repetition operator

You do not need to have an import statement in a program to use the functions in the random module.

false

A group of statements that exist within a program for the purpose of performing a specific task is a(n) __________.

function

The _________ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value. a. pop() b. key() c. value() d. get()

get()

A global variable whose value cannot be changed is known as __________. a. global constant b. local variable c. global variable d. local constant

global constant

A variable that is visible to every function in a program file is a __________. a. local variable b. universal variable c. program-wide variable d. global variable

global variable

A __________ is a diagram that gives a visual representation of the relationships between functions in a program. a. flowchart b. function relationship chart c. symbol chart d. hierarchy chart

hierarchy chart

The _________ operator can determine the existence of a key before it is used to retrieve a value. a. in b. not in c. keys() d. values()

in

This operator determines whether one string is contained inside another string. a. contains b. is_in c. == d. in

in

This is a number that identifies an item in a list. a. element b. index c. bookmark d. identifier

index

This method can be used to determine whether one set is a subset of another. a. issuperset b. issubset c. symmetric_difference d. intersection

issubset

The _________ method returns all of a dictionary's keys and their associated values as a sequence of tuples. a. keys_values() b. values() c. items() d. get()

items()

A(n) _________ is used to locate a specific value in a dictionary. a. index b. key c. integers d. string

key

In a dictionary, each element has two parts: a(n) _________ and a(n) _________. a. index, value b. value, index c. key, value d. integers, value

key, value

This is the first index in a string. a. -1 b. 1 c. 0 d. The size of the string minus one

0

The statement print('QWERTY'*2) will print _________ on the screen. a. QWERTYQWERTY b. QWERTY c. QW d. ERTY

QWERTYQWERTY

A variable created inside a function block is known as a __________. a. global variable b. local variable c. super variable d. new variable

local variable

This operator can be used to find the intersection of two sets. a. | b. & c. - d. ^

&

This operator can be used to find the difference of two sets. a. | b. & c. - d. ^

-

A list can be a dictionary key.

false

If you call the index method to locate an item in a list and the item is not found, this happens. a. A ValueError exception is raised. b. An InvalidIndex exception is raised. c. The method returns −1. d. Nothing happens. The program continues running at the next statement.

A ValueError exception is raised

This will happen if you try to use an index that is out of range for a list. a. A ValueError exception will occur. b. An IndexError exception will occur. c. The list will be erased and the program will continue to run. d. Nothing—the invalid index will be ignored.

An IndexError exception will occur

This is the last index in a list. a. 1 b. 99 c. 0 d. The size of the list minus one

The size of the list minus one

This is the last index in a string. a. 1 b. 99 c. 0 d. The size of the string minus one

The size of the string minus one

This list method adds an item to the end of an existing list. a. add b. add_to c. increase d. append

append

A(n) __________ is a piece of data that is sent into a function. a. argument b. parameter c. header d. packet

argument

When possible, you should avoid using __________ variables in a program. a. local b. global c. reference d. parameter

b. global

This statement deletes an existing key-value pair from a dictionary. a. del [key] b. del dictionary_name[value] c. del dictionary_name[key] d. del key[value]

del dictionary_name[key]

This set method removes an element but does not raise an exception if the element is not found. a. remove b. discard c. delete d. erase

discard

This term refers to an individual item in a list. a. element b. bin c. cubbyhole d. slot

element

A ValueError exception is raised if you try to retrieve a value from a dictionary using a nonexistent key.

false

A file object's writelines method automatically writes a newline ('\n') after writing each list item to the file.

false

A local variable can be accessed by all the functions in a program.

false

A statement in one function can access a local variable in another function.

false

Assume list1 references a list. After the following statement executes, list1 and list2 will reference two identical but separate lists in memory: list2 = list1

false

Boolean functions have no return type.

false

Calling a function and defining a function mean the same thing.

false

In Python you cannot write functions that accept multiple arguments.

false

In Python, strings are mutable

false

In Python, the index of the first element of the list is 1.

false

Invalid indexes in slicing expressions can produce an 'out of bound' exception.

false

Lists in Python are immutable.

false

The following statement creates an empty set: myset = ()

false

The isupper method converts a string to all uppercase characters

false

The phrase "divide and conquer" means that all of the programmers on a team should be divided and work in isolation.

false

The value of a global constant can only be changed within a function.

false

Values stored in a single dictionary cannot be of different types.

false

You can store duplicate elements in a set.

false

This string method returns true if a string contains only numeric digits and is at least one character in length. a. the digit method b. the isdigit method c. the numeric method d. the isnumber method

the isdigit method

A design technique that programmers use to break down an algorithm into functions is known as __________. a. top-down design b. code simplification c. code refactoring d. hierarchical subtasking

top-down design

A list can be an element in another list.

true

A tuple can be a dictionary key.

true

An import statement can be used to call a built-in function that is stored in a module.

true

Complex mathematical expressions can sometimes be simplified by breaking out part of the expression and putting it in a function.

true

IPO charts provide only brief descriptions of a function's input, processing, and output, but do not show the specific steps taken in a function.

true

Sets store their elements in an unordered fashion.

true

Some library functions are built into the Python interpreter.

true

String comparisons with the in and not in operators in dictionaries are case sensitive.

true

The del statement deletes an item at a specified index in a list.

true

The following statement creates an empty dictionary: mydct = {}

true

The in operator can be used to determine whether one string is not contained in another string.

true

The method isupper() returns true if a string is in uppercase and false otherwise

true

The remove method raises an exception if the specified element is not found in the set.

true

Void functions do not return any value when they are called.

true

You cannot have both keyword arguments and non-keyword arguments in a function call.

true

The method lower() returns a string with all the characters converted to lowercase

ture

This standard library function returns a random floating-point number within a speci- fied range of values. a. random b. randint c. random_integer d. uniform

uniform

This method returns a set that contains the elements of both set1 and set2. a. difference method b. union method c. intersection method d. join method

union method

A set contains a collection of _________ values. a. similar b. string c. integer d. unique

unique

This string method returns a copy of a string with all the alphabetic letters converted to uppercase. a. uppercase() b. case_upper() c. upper() d. to_upperCase()

upper()

This operator can be used to find the union of two sets. a. | b. & c. - d. ^

|


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

Graphs, Searching, and Boggle (PA4)

View Set

Restaurant Tyler Menu Test 08/21

View Set

3.4.3 Pre-Cal Graphing Polynomial Functions

View Set

BIO60 Lab Exam 1: Intro to Scientific Method

View Set