DSCI Quiz 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

list comprehensions

a concise and convenient notation for creating new lists

The _____ operator can be used to extend a list with copies of itself.

*=

To define a function with an arbitrary argument list, specify a parameter of the form .

*args (again, the name args is used by convention, but is not required).

If x is 7, the value of x after evaluating x *= 5 is ___________ .

35

Given a list numbers containing 1 through 10, del numbers[-2] removes the value _____ from the list.

9

Set method pop returns the first element added to the set.

False. Set method pop returns an arbitrary set element.

A Matplotlib _____ object manages the content that appears in a Matplotlib window.

Axes.

Why do we often work with a sample rather than the full population?

Because often the full population is unmanageably large.

___can be thought of as unordered collections in which each value is accessed through its corresponding key.

Dictionaries.

(TRUE/FALSE) A += augmented assignment statement may not be used with strings and tuples, because they're immutable.

False. A += augmented assignment statement also may be used with strings and tuples, even though they're immutable. The result is a new string or tuple, respectively.

(True/False) A fatal logic error causes a script to produce incorrect results, then continue executing.

False. A fatal logic error causes a script to terminate.

(TRUE/FALSE) A function's local variables exist after the function returns to its caller.

False. A function's local variables exist until the function returns to its caller.

(TRUE/FALSE) A view has its own copy of the corresponding data from the dictionary.

False. A view does not have its own copy of the corresponding data from the dictionary. As the dictionary changes, each view updates dynamically.

(TRUE/FALSE) Sets may be compared with only the == and != comparison operators.

False. All the comparison operators may be used to compare sets.

(True/False) If you indent a suite's statements, you will not get an IndentationError.

False. All the statements in a suite must have the same indentation. Otherwise, an IndentationError occurs.

(TRUE/FALSE) Exceptions always are handled in the function that raises the exception.

False. Although it is possible to handle an exception in the function that raises it, normally an exception is handled by a calling function on the function-call stack.

(TRUE/FALSE) Assigning to a nonexistent dictionary key causes an exception.

False. Assigning to a nonexistent key inserts a new key-value pair. This may be what you intend, or it could be a logic error if you incorrectly specify the key.

(TRUE/FALSE) Dictionaries may contain duplicate keys.

False. Dictionary keys must be unique. However, multiple keys may have the same value.

(TRUE/FALSE) Tuples can contain only immutable objects.

False. Even though a tuple is immutable, its elements can be mutable objects, such as lists.

(TRUE/FALSE) Exceptions can be raised only by code in try statements.

False. Exceptions can be raised by any code, regardless of whether the code is wrapped in a try statement.

(True/False) Function call range(1, 10) generates the sequence 1 through 10.

False. Function call range(1, 10) generates the sequence 1 through 9.

(TRUE/FALSE) Generally, displaying fewer frames-per-second yields smoother animation.

False. Generally, displaying more frames-per-second yields smoother animation.

(TRUE/FALSE) All sequences provide a sort method.

False. Immutable sequences like tuples and strings do not provide a sort method. However, you can sort any sequence without modifying it by using built-in function sorted, which returns a new list containing the sorted elements of its

(TRUE/FALSE) It's good practice to keep resources open until your program terminates.

False. It's good practice to close resources as soon as the program no longer needs them.

(TRUE/FALSE) Parameters with default parameter values must be the leftmost arguments in a function's parameter list.

False. Parameters with default parameter values must appear to the right of parameters that do not have defaults.

(TRUE/FALSE) In Python, it's possible to return to the raise point of an exception via keyword return.

False. Program control continues from the first statement after the try statement in which the exception was handled.

(True/False) Pseudocode is a simple programming language.

False. Pseudocode is not a programming language. It's an artificial and informal language that helps you develop algorithms.

(True/False) Sentinel-controlled repetition uses a counter variable to control the number of times a set of instructions executes.

False. Sentinel-control repetition terminates repetition when the sentinel value is encountered.

(TRUE/FALSE) Sets are collections of unique mutable and immutable objects.

False. Sets are collections of unique immutable objects.

(TRUE/FALSE) Slice operations that modify a sequence work identically for lists, tuples and strings.

False. Slice operations that do not modify a sequence work identically for lists, tuples and strings.

(TRUE/FALSE) The letter 'V' "comes after" the letter 'g' in the alphabet, so the comparison 'Violet' < 'green' yields False.

False. Strings are compared by their characters' underlying numerical values. Lowercase letters have higher numerical values than uppercase. So, the comparison is True.

(TRUE/FALSE) Formatted data in a text file can be updated in place because records and their fields are fixed in size.

False. Such data cannot be modified without the risk of destroying other data in the file, because records and their fields can vary in size.

(TRUE/FALSE) The + operator's sequence operands may be of any sequence type.

False. The + operator's operand sequences must have the same type; otherwise, a TypeError occurs.

(TRUE/FALSE) The actual number of frames-per-second is affected only by the millisecond interval between animation frames.

False. The actual number of frames-per-second also can be affected by the amount of work performed in each frame and the speed of your computer's processor.

(TRUE/FALSE) If a finally clause appears in a function, that finally clause is guaranteed to execute when the function executes, regardless of whether the function raises an exception.

False. The finally clause will execute only if program control enters the corresponding try suite.

(TRUE/FALSE) The function body is referred to as its suite.

False. The function body is referred to as its block.

(TRUE/FALSE) You must pass keyword arguments in the same order as their corresponding parameters in the function definition's parameter list.

False. The order of keyword arguments does not matter.

(TRUE/FALSE) An advantage of the population variance over the population standard deviation is that its units are the same as the sample values' units.

False. This an advantage of population standard deviation over population variance.

(TRUE/FALSE) Attempts to modify mutable objects create new objects.

False. This is true for immutable objects.

(TRUE/FALSE) When defining a function in IPython interactive mode, pressing Enter on a blank line causes IPython to display another continuation prompt so you can continue defining the function's block.

False. When defining a function in IPython interactive mode, pressing Enter on a blank line terminates the function definition.

(TRUE/FALSE) You cannot modify a list's contents when you pass it to a function.

False. When you pass a list (a mutable object) to a function, the function receives a reference to the original list object and can use that reference to modify the original list's contents.

(TRUE/FALSE) You must always import all the identifiers of a given module.

False. You can import only the identifiers you need by using a from...import statement.

(TRUE/FALSE) The read method always returns the entire contents of a file.

False. You may specify an argument indicating the number of characters (or bytes for a binary file) to read from the file.

_____, _____ and _____ are common operations used in functional-style programming.

Filter, map, reduce

enumerate

This function receives an iterable and creates an iterator that, for each element, returns a tuple containing the element's index and value.

(TRUE/FALSE) Once a code block terminates (e.g., when a function returns), all identifiers defined in that block "go out of scope" and can no longer be accessed.

True

(TRUE/FALSE) When an argument with a default parameter value is omitted in a function call, the interpreter automatically passes the default parameter value in the call.

True

algorithm

a procedure for solving a problem in terms of action and order

symmetric difference between two sets

a set consisting of the elements of both sets that are not in common with one another. ^ operator

method append

add a new item to the end of a list

list method extend

add all the elements of another sequence to the end of a list

Method insert

adds a new item at a specified index

A(n) ___________ is a procedure for solving a problem. It specifies the ___________ to execute and the ___________ in which they execute.

algorithm, actions, order

A(n) __________ specifies everything that should change during one plot update. Stringing together many of these over time creates the animation effect.

animation frame.

You can simulate a stack with a list, using methods _____ and _____ to add and remove elements, respectively, only at the end of the list.

append, pop.

The Seaborn function _____ displays data as a bar chart.

barplot.

To sort a list in descending order

call list method sort with the optional keyword argument reverse set to True (False is the default): numbers.sort(reverse=True)

For a list numbers, calling method _____ is equivalent to numbers[:] = [].

clear

principle of least privilege

code should be granted only the amount of privilege and access that it needs to accomplish its designated task, but no more.

The _____ format specifier indicates that a number should be displayed with thousands separators.

comma (,).

A function with multiple parameters specifies them in a(n) .

comma-separated list.

greedy evaluation

create lists immediately when you execute them

generator expression

creates an iterable generator object that produces values on demand. This is known as lazy evaluation

method clear

delete all the elements in a list

Method remove

deletes the first element with a specified value

What does an expression of the following form do when the key is in the dictionary?

dictionaryName[key] = value It updates the value associated with the key, replacing the original value.

method clear

empties the set on which it's called

sorting

enables you to arrange data either in ascending or descending order.

To add all the elements of a sequence to the end of a list, use list method _____, which is equivalent to using +=.

extend.

(TRUE/FALSE) The == comparison evaluates to True only if both dictionaries have the same key-value pairs in the same order.

false. The == comparison evaluates to True if both dictionaries have the same key-value pairs, regardless of their order.

A(n) ___________ is a graphical representation of an algorithm.

flowchart.

A list comprehension's _____ clause iterates over the specified sequence.

for

The built-in function returns an object's unique identifier.

id

A list comprehension's _____ clause filters sequence elements to select only those that match a condition.

if

Two sets are disjoint

if they do not have any common elements

Python's string and tuple sequences are _____—they cannot be modified.

immutable

The operator tests whether its right operand's iterable contains its left operand's value.

in

Operators _____ and _____ determine whether a sequence contains or does not contain a value, respectively.

in, not in.

Sentinel-controlled repetition is called ___________ because the number of repetitions is not known before the loop begins executing.

indefinite repetition.

Many of the scripts you'll write can be decomposed into three phases: ___________ , ___________ and ___________ .

initialization, processing, termination.

Set method add

inserts its argument if the argument is not already in the set

The classes that Python uses to create file objects are defined in the Python Standard Library's__ module.

io

Dictionary method returns each key-value pair as a tuple.

items

Dictionary method __________returns an unordered list of the dictionary's keys.

keys

A stack's items are removed in order.

last-in, first-out (LIFO).

A generator expression is _____—it produces values on demand.

lazy

sort

modifies a list to arrange its elements in ascending order

A(n) defines related functions, data and classes. A(n) groups related modules.

module, package.

Every Python source code (.py) file you create is a(n) .

module.

Assume you have a list called names. The slice expression _____ creates a new list with the elements of names in reverse order.

names[::-1]

A field width specifies the ___________ to use when displaying a value.

number of character positions.

if...else statement

performs an action if a condition is True or performs a differentaction if the condition is False.

if statement

performs an action if a condition is True or skips the action if the condition is False.

if...elif...else statement

performs one of many different actions, depending on the truth or falsity of several conditions

A subset is a(n) subset of another set if all the subset's elements are in the other set and the other set has more elements.

proper.

Files

provide long-term retention of typically large amounts of data, even after the program that created the data terminates, so data maintained in files is persistent.

modify_elements

receives a reference to a list and multiplies each of the list's element values by 2

the stack operations for adding an item to a stack and removing an item from a stack are known as and , respectively.

push, pop.

Use the ____statement to indicate that a problem occurred at execution time.

raise

The statement that raises an exception is sometimes called the ____ of the exception.

raise point

The element of chance can be introduced into computer applications using module .

random .

Function ___________ generates a sequence of integers.

range

A(n) _____ processes a sequence's elements into a single value, such as their count, total or average.

reduction.

The os module's____ and____ functions delete a file and specify a new name for a file, respectively.

remove, rename.

Set method remove

removes its argument from the set

Method discard

removes its argument from the set but does not cause an exception if the value is not in the set.

while statement

repeats an action (or a group of actions) as long as a condition remains True.

for statement

repeats an action (or a group of actions) for every item in a sequence of items.

A(n) ___________ describes what a program is supposed to do, but not howthe program should do it.

requirements statement.

Closing a file helps prevent a(n)____ in which the file resource is not available to other programs because a program using the file never closes it.

resource leak.

method copy

returns a new list containing a shallow copy of the original list

Built-in function reversed

returns an iterator that enables you to iterate over a sequence's values backward.

To sort a list in descending order, call list method sort with the optional keyword argument _____ set to True.

reverse.

Built-in function _____ returns an iterator that enables you to iterate over a sequence's values backward.

reversed.

method reverse

reverses the contents of a list in place, rather than creating a reversed copy

In a two-dimensional list, the first index by convention identifies the _____ of an element and the second index identifies the _____ of an element.

row, column.

An identifier's describes the region of a program in which the identifier's value can be accessed.

scope

An identifier's describes the region of a program in which the identifier's value can be accessed.

scope.

method count

searches for its argument and returns the number of times it is found

The random module's function enables reproducibility of random sequences.

seed

A file object's______ method can be used to reposition the file-position pointer.

seek

You can write all programs using three forms of control—___________ , ___________ and ___________ .

sequential execution, selection statements, repetition statements.

Converting objects to JSON text format is known as , and reconstructing the original Python object from the JSON text is known as .

serialization, deserialization.

You can create a set from another collection of values by using the built-in function.

set

union of two sets

set consisting of all the unique elements from both sets. | operator

intersection of two sets

set consisting of all the unique elements that the two sets have in common. & operator

difference between two sets

set consisting of the elements in the left operand that are not in the right operand. - operator

The Matplotlib function _____ displays a plot window from a script.

show.

Program control

specifies the order in which statements (actions) execute in a program

String method tokenizes a string using the delimiter provided in the method's string argument.

split

An uncaught exception in a function causes _____ . The function's stack frame is removed from the function-call stack.

stack unwinding.

Single-entry/single-exit (one way in/one way out) control statements

the exit point of one connects to the entry point of the next

To prevent an IndexError when calling pop on a list, first ensure that _____.

the list's length is greater than 0.

(TRUE/FALSE) By default, iterating through a file object with a for statement reads one line at a time from the file and returns it as a string.

true

(TRUE/FALSE) JSON is both a human-readable and computer-readable format that makes it convenient to send and receive objects across the Internet.

true

(TRUE/FALSE) Once a code block terminates (e.g., when a function returns), all identifiers defined in that block "go out of scope" and can no longer be accessed.

true

(TRUE/FALSE) Python does not have constants.

true

(TRUE/FALSE) Tuples can contain lists and other mutable objects. Those mutable objects can be modified when a tuple is passed to a function.

true

A while statement performs its suite while some condition remains True.

true

A sequence's elements can be _____ by assigning the sequence to a comma-separated list of variables.

unpacked.

Set method performs a union operation, modifying the set on which it's called.

update

del statement

used to remove elements from a list and to delete variables from the interactive session

The _____implicitly releases resources when its suite finishes executing.

with


Kaugnay na mga set ng pag-aaral

NUR 243 Prep U Ch 26 Nursing Care of the Child With an Alteration in Metabolism/Endocrine Disorder

View Set

"Why couldn't I have been named Ashley" review

View Set

Unit 2- Biological Bases of Behavior

View Set