486 multiple choice

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What should the question mark (?) in the following for statement be replaced with, so that the statements will calculate 5!: In [1]: factorial = 1 In [2]: for number in range(5, 0, ?): ...: factorial *= number ...: In [3]: factorial Out[3]: 120 1 0 -1 None of the above

-1

Which of the following would be accepted by a program strictly looking for four integers of data in CSV format? 100, 85 77,9 100,85,,77,9 '100,85,77,9'=' 100,85, 77,9

100,85, 77,9

Which of the following statements is false? You can create an array from a range of elements, then use array method reshape to transform the one-dimensional array into a multidimensional array. The following code creates an array containing the values from 1 through 20, then reshapes it into four rows by five columns: np.arange(1, 21).reshape(4, 5) A 24-element one-dimensional array can be reshaped into a 2-by-12, 8-by-3 or 4-by-8 array, and vice versa. All of the above are true.

A 24-element one-dimensional array can be reshaped into a 2-by-12, 8-by-3 or 4-by-8 array, and vice versa.

The following code creates a list, then uses del to remove its first element: numbers = list(range(0, 10))del numbers[1] True False

False

Which of the following statements is true with respect to displaying an array of 1000 items or more? NumPy always drops the middle rows and middle columns from the output. NumPy always drops the middle rows from the output. NumPy always drops the middle columns from the output. NumPy drops the middle rows, middle columns or both from the output.

NumPy drops the middle rows, middle columns or both from the output.

Which of the following statements is false? The d presentation type in the following f-string formats strings as integer values: f'{10:d}' The integer presentation types b, o and x or X format integers using the binary, octal or hexadecimal number systems, respectively. The c presentation type in the following f-string formats an integer character code as the corresponding character: f'{65:c} {97:c}' If you do not specify a presentation type, as in the second placeholder below, non-string values like the integer 7 are converted to strings: f'{"hello":s} {7}'

The d presentation type in the following f-string formats strings as integer values: f'{10:d}'

Two sets are disjoint if they do not have any common elements. You can determine this with the set type's isdisjoint method. What values are actually displayed for ??? in Out[1] and Out[2]: In [1]: {1, 3, 5}.isdisjoint({2, 4, 6})Out[1]: ??? In [2]: {1, 3, 5}.isdisjoint({4, 6, 1})Out[2]: ??? False, False False, True True, False True, True

True, False

Which of the following statements is false? Tuples are immutable. Tuples must store heterogeneous data. A tuple's length is its number of elements. A tuple's length cannot change during program execution.

Tuples must store heterogeneous data.

By default, the re module's sub function replaces only the first occurrence of a pattern with the replacement text you specify. The statement re.sub(r'\t', ', ', '1\t2\t3\t4') returns '1, 2\t3\t4' true false

false

The following code creates a Series of student grades from a list of integers: import pandas as pd grades = pd.Series([87, 100, 94]) By default, a Series has integer indexes numbered sequentially from 1, and the Series argument may be a tuple, a dictionary, an array, another Series or a single value. true false

false

The following code creates a dictionary with the country-name keys 'Finland', 'South Africa' and 'Nepal' and their corresponding Internet country code values 'fi', 'za' and 'np': country_codes = {'Finland', 'fi', 'South Africa', 'za', 'Nepal', 'np'} true false

false

The following code formats the float value 17.489 rounded to the hundredths position: '{:.3f}'.format(17.489) true false

false

The following code replaces tab characters with commas: values = '1\t2\t3\t4\t5' values.replace('\t', ', ') true false

false

The following code implements a simple linear search. In [1]: def linear_search(data, search_key): ...: for index, value in enumerate(data):: ...: if value == search_key: ...: return ? ...: return -1 ...: ...: In the statement return ?, what should the ? be? data search_key index None of the above

index

The json module's ______________ function reads the entire JSON contents of its file object argument and converts the JSON into a Python object. This is known as ______________ the data. read, serializing load, serializing load, deserializing read, deserializing

load, deserializing

ssume the following array definitions: import numpy as np integers = np.array([[1, 2, 3], [4, 5, 6]]) floats = np.array([0.0, 0.1, 0.2, 0.3, 0.4]) The attribute ___________contains an array's number of dimensions and the attribute contains a _________specifying an array's dimensions: dim, size, list ndim, shape, tuple dim, size, tuple ndim, shape, list

ndim, shape, tuple

If the contents of a file should not be modified, open the file for —another example of the principle of least privilege. This prevents the program from accidentally modifying the file. writing only reading only reading and writing none of the above

reading only

We use array method ________ to produce two-dimensional arrays from one-dimensional ranges. shape rectangularize reshape None of the above.

reshape

A dictionary is an unordered collection which stores key-value pairs that map immutable keys to values, just as a conventional dictionary maps words to definitions. true false

true

Assuming the following array grades: grades = np.array([[87, 96, 70], [100, 87, 90], [94, 77, 90], [100, 81, 82]]) To select multiple sequential rows, use slice notation, as in grades[0:2] and to select multiple non-sequential rows, use a list of row indices, as in grades[[1, 3]] true false

true

Based on the string sentence = '\t \n This is a test string. \t\t \n' The following code snippets first use method lstrip to remove only leading whitespace from sentence: sentence.lstrip() then use method rstrip to remove only trailing whitespace: sentence.rstrip() true false

true

Consider a Series of hardware-related strings: hardware = pd.Series(['Hammer', 'Saw', 'Wrench']) The following code uses the Series str attribute to invoke string method upper on every Series element, producing a new Series containing the uppercase versions of each element in hardware: hardware.str.upper() true false

true

For a two-dimensional array grades in which each row represents one student's grades on several exams, we can calculate each student's average grade with: grades.mean(axis=1) true false

true

If numbers is a five-element integer array, numbers * 2 is equivalent to: numbers * [2, 2, 2, 2, 2] true false

true

Sets may contain only immutable objects, like strings, ints, floats and tuples that contain only immutable elements. true false

true

The array methods sum, min, max, mean, std (standard deviation) and var (variance) are each functional-style programming reductions. true false

true

Lists may store ________ data, that is, data of many different types. parallel heterogeneous homogeneous None of the above.

heterogeneous

Consider a Series of hardware-related strings: hardware = pd.Series(['Hammer', 'Saw', 'Wrench']) The following code calls string method contains on each element to determine whether the value of each element contains a lowercase 'a': hardware.str.contains('a') and returns a Series containing bool values indicating the contains method's result for each element. true false

true

When you call describe on a DataFrame containing both numeric and non-numeric columns, describe calculates the statistics below only for the numeric columns. true false

true

lement-wise operations are applied to every array element, so given an integer array named numbers, the expression numbers * 2 multiplies every element by 2, and the expression numbers ** 3 cubes every element. true false

true

Which of the following statement(s) will reverse the order of the below items list numbers: numbers = [2, 3, 4, 6, 7, 13, 17, 19] ? reversed_numbers = [item for item in reversed(numbers)] The following code concisely creates a new list in reverse order: numbers[::-1] To sort a list in descending order, call list method sort with the optional keyword argument reverse=True. numbers.sort(reverse=True) All of the above statements are true.

All of the above statements are true.

Which of the following statements about sorting unique items is false? Sorting data (i.e., placing the data in a particular order—ascending or descending—is one of the most important types of computing applications. An important item to understand about sorting unique values is that the end result—the sorted array—will be the same no matter which algorithm you use to sort the array. The choice of algorithm affects only the run time of the program. Selection sort and insertion sort—are relatively simple to program but inefficient. Merge sort—is much faster than selection sort and insertion sort but harder to program. All of the above statements are true.

An important item to understand about sorting unique values is that the end result—the sorted array—will be the same no matter which algorithm you use to sort the array. The choice of algorithm affects only the run time of the program

Preparing data for analysis is called___________ or_________ . data wrangling data munging Both (a) and (b). Neither (a) nor (b).

Both (a) and (b).

Consider the following code: In [1]: s1 = 'happy' In [2]: s2 = 'birthday' In [3]: s1 += ' ' + s2 In [4]: s1 Out[4]: 'happy birthday' In [5]: symbol = '>' In [6]: symbol *= 5 In [7]: symbol Out[7]: '>>>>>' Which snippet(s) in this interactive session appear to modify existing strings, but actually create new string objects? Only snippet [3]. Only snippet [5]. Both snippets [5] and [6]. Both snippets [3] and [6].

Both snippets [3] and [6].

Which of the following statements is false? DataFrames have a describe method that calculates basic descriptive statistics for the data and returns them as two-dimensional array. In a DataFrame, the statistics are calculated by column. Method describe nicely demonstrates the power of array-oriented programming with a functional-style call—Pandas handles internally all the details of calculating these statistics for each column. You can control the precision of floating-point values and other default settings with pandas' set_option function.

DataFrames have a describe method that calculates basic descriptive statistics for the data and returns them as two-dimensional array.

Which of the following statements is false? For big data applications, you'll also want to choose algorithms that are easy to sequentialize—that will enable you to put lots of processors to work simultaneously. The simplest and most apparent algorithms often perform poorly—developing more sophisticated algorithms can lead to superior performance. All of the above statements are true. None of the above statements are true.

For big data applications, you'll also want to choose algorithms that are easy to sequentialize—that will enable you to put lots of processors to work simultaneously.

IF ITS THE WALLY EVA SAM CHART ITS TRUE

IF ITS THE WALLY EVA SAM CHAR ITS TRUE

Which of the following statements is false? You can delete a key-value pair from a dictionary with the del statement You can remove a key-value pair with the dictionary method pop, which returns the value for the removed key. Method clean deletes the dictionary's key-value pairs: Operators in and not in can determine whether a dictionary contains a specified key.

Method clean deletes the dictionary's key-value pairs:

Which of the following statements are false? JSON (JavaScript Object Notation) is a data-interchange format readable only by computers and used to represent objects (such as dictionaries, lists and more) as collections of name-value pairs. Many libraries you'll use to interact with cloud-based services such as Twitter, IBM Watson and others communicate with your applications via JSON objects. JSON can represent objects of custom classes. JSON has become the preferred data format for transmitting objects across platforms. This is especially true for invoking cloud-based web services, which are functions and methods that you call over the Internet.

JSON (JavaScript Object Notation) is a data-interchange format readable only by computers and used to represent objects (such as dictionaries, lists and more) as collections of name-value pairs.

Which of the following statements is false? NumPy arrays use only zero-based integer indexes. Like arrays, Series use only zero-based integer indexes. Series may have missing data, and many Series operations ignore missing data by default. All of the above statements are true.

Like arrays, Series use only zero-based integer indexes.

Which of the following statements is false? Pandas is the most popular library for dealing with mixed data types, customized indexing, missing data, and data that needs to be manipulated into forms appropriate for the databases and data analysis packages. Data science presents unique demands for which more customized data structures are required. NumPy's array is optimized for heterogeneous numeric data that's accessed via integer indices. Pandas provides two key collections—Series for one-dimensional collections and DataFrames for two-dimensional collections.

NumPy's array is optimized for heterogeneous numeric data that's accessed via integer indices.

Which of the following statements is false? As in lists and arrays, the first character in a text file and byte in a binary file is located at position 0, so in a file of n characters or bytes, the highest position number is n - 1. Python views text files and binary files (for images, videos and more) as sequences of bytes. For each file you open, Python creates a file object that you'll use to interact with the file. All of the above statements are true.

Python views text files and binary files (for images, videos and more) as sequences of bytes.

Which of the following statements is false? You can determine the number of items in a set with the built-in len function. Sets are not iterable, so you cannot process each set element with a for loop. You can check whether a set contains a particular value using the in and not in operators. Sets are unordered, so there's no significance to the iteration order.

Sets are not iterable, so you cannot process each set element with a for loop.

Consider this text from Shakespeare: soliloquy = 'To be or not to be, that is the question' Which of the following statements is false? String method index searches for a substring within a string and returns the first index at which the substring is found; otherwise, a ValueError occurs. The following code returns 3: soliloquy.index('be') String method rindex performs the same operation as index, but searches from the end of the string and returns the last index at which the substring is found; otherwise, a Value-Error occurs. The following code returns 3: soliloquy.rindex('be') String methods find and rfind perform the same tasks as index and rindex but, if the substring is not found, return -1 rather than causing a Value-Error. All of the above statements are true.

String method rindex performs the same operation as index, but searches from the end of the string and returns the last index at which the substring is found; otherwise, a Value-Error occurs. The following code returns 3: soliloquy.rindex('be')

Which of the following statements about DataFrames is false? The index can be a slice. In the following slice containing, the range specified includes the high index ('Test3'): grades.loc['Test1':'Test3'] When using slices containing integer indices with iloc, the range you specify excludes the high index (2): grades.iloc[0:2] To select specific rows, use a tuple rather than slice notation with loc or iloc. All of the above statements are true.

To select specific rows, use a tuple rather than slice notation with loc or iloc.

Which of the following statements is false? Searching data involves determining whether a value (referred to as the search key) is present in the data and, if so, finding its location. Two popular search algorithms are the simple binary search and the faster but more complex linear search. Sorting places data in ascending or descending order, based on one or more sort keys. Each of the above statements is true.

Two popular search algorithms are the simple binary search and the faster but more complex linear search.

Which of the following statements is false? Variables, lists, tuples, dictionaries, sets, arrays, pandas Series and pandas DataFrames offer long-term data storage. Computers store files on secondary storage devices, including solid-state drives, hard disks and more. Some popular text file formats are plain text, JSON (JavaScript Object Notation) and CSV (comma-separated values). All of the above statements are true.

Variables, lists, tuples, dictionaries, sets, arrays, pandas Series and pandas DataFrames offer long-term data storage.

The following code creates an accounts.txt file and write five client records to the file. Generally, records in text files are stored one per line, so we end each record with a newline character: with open('accounts.txt', mode='w') as accounts: accounts.write('100 Jones 24.98\n') accounts.write('200 Doe 345.67\n') accounts.write('300 White 0.00\n') accounts.write('400 Stone -42.16\n') accounts.write('500 Rich 224.62\n') You can also write to a file with print (which automatically outputs a \n), as in print('100 Jones 24.98', file=accounts) true false

true

The following code, which has a dictionary with unique values, reverses the key-value pairs: months = {'January': 1, 'February': 2, 'March': 3} months2 = {number: name for name, number in months.items()} true false

true

The following update call receives a dictionary key-value pair to insert or update: country_codes.update({'Australia': 'ar'}) Provided an incorrect country code for Australia. The following code corrects this by using a keyword argument to update the value associated with 'Australia': country_codes.update(Australia='au') true false

true

The names keyword argument specifies the DataFrame's column names. If you do not supply the names keyword argument, read_csv assumes that the CSV file's first row is a comma-delimited list of column names. true false

true

Which of the following would be displayed for ??? by Out[3]? In [1]: numbers = list(range(10)) + list(range(5)) In [2]: numbers Out[2]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4] In [3]: set(numbers) Out[3]: ??? [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}


Ensembles d'études connexes

Drivers Test module 1, Drivers Ed module 2, Drivers Ed module 3, Drivers Ed Module 4, Drivers Ed module 5, Drivers Ed module 6, Drivers Ed module 7, Drivers Ed module 8, Drivers Ed module 10, Drivers Ed module 9, Driver Ed module 11, Drivers Ed modul...

View Set

Urinary/Reproductive Systems Evolve

View Set

Google Cloud Certified Associate Cloud Engineer

View Set