python final exam
Which of the following statements a), b) or c) is false? All of the above statements are true. You can access a global variable's value inside a function. By default, you cannot modify a global variable in a function-when you first assign a value to a variable in a function's block, Python creates a new local variable. To modify a global variable in a function's block, you must use a global statement to declare that the variable is defined in the global scope.
All of the above statements are true.
Which of the following statements about the cloud is false?
Azure is Google's set of cloud-based services.
Which of the following statements a), b) or c) is false? In an f-string, you can optionally follow a replacement-text expression with a colon (:) and a format specifier that describes how to format the replacement text. The format specifier .2f formats data as a floating-point number (f) with two digits to the right of the decimal point (.2). Formatting floating-point data with .2f rounds it to the tenths position. All of the above statements are true.
Formatting floating-point data with .2f rounds it to the tenths position.
Which of the following popular Python data science libraries are central to machine learning, deep learning and/or reinforcement learning:
all of the above
Which of the following statements a), b) or c) is false?
Almost any verb can be reasonably represented as a software object in terms of attributes (e.g., name, color and size) and behaviors (e.g., calculating, moving and communicating).
A program might call a bank-account object's deposit ________ to increase the account's balance.
method
Assume x is 3, y is 7.1 and z is '11.5'. Which of the following statements is incorrect?
the value of z is 11.5
Python provides two iteration statements-________ and ________.
while, for
What does the following for statement print? for counter in range(10): print(counter, end=' ') It doesn't run because it's syntactically incorrect. 0 1 2 3 4 5 6 7 8 9 10 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
What does the following line of code display?print(10, 20, 30, sep=', ') 10 20 30 102030 10, 20, 30 10,20,30
10, 20, 30
What value is produced when Python evaluates the following expression?5 * (12.7 - 4) / 2
21.75
The chained comparison 3 < y <= 11 is false for which of the following values of y: 11 10 3 4
3
Which of the following statements is false. Variables for totaling and counting normally are initialized to zero before they're used. Once a correct algorithm has been specified, creating a working Python program from the algorithm is typically straightforward. Experience has shown that the most challenging part of solving a problem on a computer is developing an algorithm for the solution. A requirements statement describes how a program should operate but not what the program is supposed to do.
A requirements statement describes how a program should operate but not what the program is supposed to do.
Which of the following statements is false? Grades on a quiz are typically nonnegative integers between 0 and 100, so the value —1 is an acceptable sentinel value for grades data. Sentinel-controlled iteration is often called indefinite iteration because the number of iterations is not known before the loop begins executing. A sentinel value must match one acceptable input value. A sentinel value indicates end of data entry."
A sentinel value must match one acceptable input value.
Which of the following statements is false? To avoid using \' and \" inside strings, you can enclose such strings in triple quotes. A string delimited by single quotes may include double-quote characters:print('Display "hi" in quotes') A string delimited by double quotes may include single quote characters:print("Display the name O'Brien") A string delimited by double quotes may not include double quotes.
A string delimited by double quotes may not include double quotes.
Which of the following statements is incorrect ? The range of values is simply the minimum through the maximum value. Much of data science is devoted to getting to know your data. min(17, 19, 23, 29, 31, 37, 43) is a valid call to built-in function min. all of the above are correct
All of the above are correct.
Which of the following statements a), b) or c) is false? To use Decimal, you must first import its module, as inimport decimaland refer to the Decimal type as decimal.Decimal, or you must indicate a specific capability to import using from...import, as in:from decimal import Decimalwhich imports only the type Decimal from the decimal module so that you can use it in your code. The Python Standard Library is divided into modules-groups of related capabilities. The decimal module defines type Decimal and its capabilities. All of the above statements are true.
All of the above statements are true.
Which of the following statements a), b) or c) is false? An algorithm is a procedure for solving a problem in terms of the actions to execute, and the order in which these actions execute. All of the above statements are true. You can solve any computing problem by executing a series of actions in a specific order. Program control specifies the order in which statements (actions) execute in a program.
All of the above statements are true.
Which of the following statements a), b) or c) is false? You form each Python program by combining as many control statements of each type as you need for the algorithm the program implements. All of the above statements are true. You can construct any Python program from only six different forms of control (sequential execution, and the if, if...else, if...elif...else, while and for statements). You combine these in only two ways (control-statement stacking and control-statement nesting). This is the essence of simplicity. With 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. This is similar to the way a child stacks building blocks-hence, the term control-statement stacking.
All of the above statements are true.
Which of the following statements about the IPython session below is true?In [1]: gender = 'Female'In [2]: age = 70In [3]: if gender == 'Female' and age >= 65: ...: print('Senior female') ...: Senior female The combined condition can be made clearer by adding redundant (unnecessary) parentheses(gender == 'Female') and (age >= 65) All of the above statements are true. The session defines two variables, then tests a condition that's True if and only if both simple conditions are True-if either (or both) of the simple conditions is False, the entire and expression is False. The right side of the and operator evaluates only if the left side is True.
All of the above statements are true.
Which of the following statements is false? Strings containing characters are True and empty strings ('', "" or """""") are False. All of the above statements are true. A condition which evaluates to a nonzero value is considered to be True, and a condition which evaluates to a value of zero is considered to be False. Any expression may be evaluated as True or False.
All of the above statements are true.
Which of the following Python concepts are demonstrated directly or indirectly by the following code: In [1]: x = 7 Out[1]: int In [2]: type(x) Out[2]: int In [3]: x = 4.1 In [4]: type(x) Out[4]: float In [5]: x = 'dog' In [6]: type(x) Out[6]: str Python uses dynamic typing-it determines the type of the object a variable refers to while executing your code. All of the above. Over its lifetime a variable can be bound to different objects, even objects of different types. Python creates objects in memory and removes them from memory as necessary. This removal process-called garbage collection-helps ensure that memory is available for new objects you create.
All of the above.
Which of the following statements about functional-style programming is false? With functional-style programming capabilities you can write code that is more concise, clearer and easier to debug (find and correct errors). Other reductions you'll see include the sum, average, variance and standard deviation of a collection of values. The min and max functions are examples of a functional-style programming concept called reduction. They reduce a collection of values to a single value. All reductions are built into Python-you cannot define custom reductions.
All reductions are built into Python-you cannot define custom reductions.
Which of the following statements about energy consumption is false?
Another enormous electricity consumer is the blockchain-based cryptocurrency Bitcoin-processing just one Bitcoin transaction uses approximately the same amount of energy as powering the average American home for a year.
Which of the following statements is false about Berners lee
Berners-Lee also wrote communication protocols such as JavaScript Object Notation (JSON) to form the backbone of his new hypertext information system, which he referred to as the World Wide Web.
What does the int function attempt to do in the following code? value = input('Enter an integer: ')value = int(value) Convert a non-object to an object. Convert a string to an integer. Convert an integer to a string. None of the above.
Convert a string to an integer.
Which of the following statements is false? The following if statement uses the == comparison operator to determine whether the values of variables number1 and number2 are equal:if number1 == number2: print(number1, 'is equal to', number2) Each if statement consists of the keyword if, the condition to test, and a colon (:) followed by an indented body called a suite. Each suite contains zero or more statements. Forgetting the colon (:) after the condition is a common syntax error.
Each suite contains zero or more statements.
Which of the following statements is false? The following statement creates x and uses the assignment symbol (=) to give x a value.x = 7 Every statement stops at the end of the line in which it begins. Once x and y are created and assigned values, you can use the values in expressions like:x + y Variables store values for later use in your code.
Every statement stops at the end of the line in which it begins.
Which of the following statements about arithmetic operators is false?
Expressions containing an integer and a floating-point number are mixed-type expressions-these always produce an integer.
Which of the following statements is false? Financial institutions like banks that deal with millions or even billions of transactions per day have to tie out their transactions "to the penny." Floating-point numbers can represent some but not all monetary amounts with to-the-penny precision. Floating-point values are stored and represented precisely in binary format. Many applications require precise representation of numbers with decimal points. For monetary calculations and other applications that require precise representation and manipulation of numbers with decimal points, the Python Standard Library provides type Decimal, which uses a special coding scheme to solve the problem of "to-the-penny precision." Banks also have to deal with other issues such as using a fair rounding algorithm when they're calculating daily interest on accounts. Type Decimal offers such capabilities.
Floating-point values are stored and represented precisely in binary format.
Which of the following statements about AI is false:
For many decades, AI has been a field with solutions and no problems.
Which of the following statements is false? For single-digit year values 1—9, the format specifier >2 displays a value followed by the space character, thus right aligning the years in the first column. The placeholder {year:>2} uses the format specifier >2 to indicate that year's value should be right aligned (>) in a field of width 2-the field width specifies the number of character positions to use when displaying the value. The format specifier 10.2f in the placeholder {amount:>10.2f} formats amount as a floating-point number (f) right aligned (>) in a field width of 10 with a decimal point and two digits to the right of the decimal point (.2). Formatting a column of amounts this way aligns their decimal points vertically, as is typical with monetary amounts. The following statement uses an f-string with two placeholders to format year and amount:print(f'{year:>2}{amount:>10.2f}')
For single-digit year values 1—9, the format specifier >2 displays a value followed by the space character, thus right aligning the years in the first column.
Assuming the following function definition, which of the following statements is false?def rectangle_area(length=2, width=3): """Return a rectangle's area.""" return length * width For the following call, the interpreter passes the default parameter value 3 for the width as if you had called rectangle_area(3, 10):rectangle_area(10) Any parameters with default parameter values must appear in the parameter list to the right of parameters that do not have defaults. The following call to rectangle_area has arguments for both length and width, so IPython ignores the default parameter values:rectangle_area(10, 5) You specify a default parameter value by following a parameter's name with an = and a value.
For the following call, the interpreter passes the default parameter value 3 for the width as if you had called rectangle_area(3, 10):rectangle_area(10)
Which of the following statements a), b) or c) is false? Identifiers with global scope can be used in a .py file or interactive session anywhere after they're defined. Identifiers defined outside any function (or class) have script scope-these may include functions, variables and classes. All of the above statements are true.
Identifiers defined outside any function (or class) have script scope-these may include functions, variables and classes.
Which of the following statements is false? A line that begins with the hash character (#) is a comment. The Style Guide for Python Code states that each script should start with a docstring that explains the script's purpose. Comments do not cause the computer to perform any action when the code executes. If a line has a comment on it, that comment must begin the line with a hash character (#).
If a line has a comment on it, that comment must begin the line with a hash character (#).
Which of the following statements is false? The argument of each of the statistics module's mean, median and mode functions must be an iterable. If a list's number of values is even, median returns the mode of the two middle values. To help confirm the median and mode values of a grades list, you can use the built-in sorted function to get a copy of grades with its values arranged in increasing order, as in the following session, which makes it clear that both the median and the mode are 85:In [1]: grades = [85, 93, 45, 89, 85]In [2]: sorted(grades)Out[2]: [45, 85, 85, 89, 93] The mode function causes a Statistics Error for lists like[85, 93, 45, 89, 85, 93]in which there are two or more "most frequent" values. Such a set of values is said to be bimodal.
If a list's number of values is even, median returns the mode of the two middle values.
Which of the following statements is false? Python applies the operators in arithmetic expressions according to the rules of operator precedence, which are generally the same as those in algebra. Parentheses have the highest level of precedence, so expressions in parentheses evaluate first-thus, parentheses may force the order of evaluation to occur in any sequence you desire. If an expression contains several exponentiation operations, Python applies them from left to right. In expressions with nested parentheses, such as (a/(b-c)), the expression in the innermost parentheses (that is, b-c) evaluates first.
If an expression contains several exponentiation operations, Python applies them from left to right.
Which of the following statements is false? Programs that are not uniformly indented are hard to read. If you have more than one statement in a suite, those statements do not need to have the same indentation. Indenting a suite is required; otherwise, an IndentationError syntax error occurs. Sometimes error messages may not be clear. The fact that Python calls attention to the line is often enough for you to figure out what's wrong.
If you have more than one statement in a suite, those statements do not need to have the same indentation.
Which of the following statements is false? In operator expressions that use the and operator, make the condition that's more likely to be True the leftmost condition-in or operator expressions, make the condition that's more likely to be False the leftmost condition-each of these tactics can reduce a program's execution time. The following condition stops evaluating immediately if semester_average is greater than or equal to 90 because the entire expression must be True:semester_average >= 90 or final_exam >= 90 The following condition stops evaluating immediately if gender is not equal to 'Female' because the entire expression must be False. If gender is equal to 'Female', execution continues, because the entire expression will be True if the age is greater than or equal to 65:gender == 'Female' and age >= 65 Python stops evaluating an and-expression as soon as it knows whether the entire condition is False. Python stops evaluating an or-expression as soon as it knows whether the entire condition is True.
In operator expressions that use the and operator, make the condition that's more likely to be True the leftmost condition-in or operator expressions, make the condition that's more likely to be False the leftmost condition-each of these tactics can reduce a program's execution time.
Which of the following statements a), b) or c) is false? All of the above statements are true. The following code shows two statements in the else suite of an if...else statement:grade = 49if grade >= 60:print('Passed')else:print('Failed')print('You must take this course again') In the code of Part (a), even if you do not indent the else suite's second print statement, it's still in the else's suite. So, the code runs correctly. In the code in Part (a), grade is less than 60, so both statements in the else's suite execute.
In the code of Part (a), even if you do not indent the else suite's second print statement, it's still in the else's suite. So, the code runs correctly.
Which of the following statements is false? When we say that Python applies certain operators from left to right, we are referring to the operators' grouping. All Python operators of the same precedence group left-to-right except for the exponentiation operator (**), which groups right-to-left. In the following expression, the addition operators (+) group as if we parenthesized the expression as a+(b+c). You can use redundant parentheses to group subexpressions to make expressions clearer. For example, the second-degree polynomialy = a * x ** 2 + b * x + ccan be parenthesized, for clarity, asy = (a * (x ** 2)) + (b * x) + c
In the following expression, the addition operators (+) group as if we parenthesized the expression as a+(b+c).
Which of the following statements is false? In the following session, snippets [2] and [5] produce the same results purely by coincidence:In [1]: import randomIn [2]: random.seed(32)In [3]: for roll in range(10): ...: print(random.randrange(1, 7), end=' ') ...: 1 2 2 3 6 2 4 1 6 1In [4] for roll in range(10): ...: print(random.randrange(1, 7), end=' ') ...: 1 3 5 3 1 5 6 4 3 5In [5] random.seed(32)In [6]: for roll in range(10): ...: print(random.randrange(1, 7), end=' ') ...: 1 2 2 3 6 2 4 1 6 1 When you're debugging logic errors in programs that use randomly generated data, it can be helpful to use the same sequence of random numbers until you've eliminated the logic errors, before testing the program with other values. Function randrange actually generates pseudorandom numbers, based on an internal calculation that begins with a numeric value known as a seed. You can use the random module's seed function to seed the random-number generator yourself-this forces randrange to begin calculating its pseudorandom number sequence from the seed you specify. Choosing the same seed will cause the random number generator to generate the same sequence of random numbers.
In the following session, snippets [2] and [5] produce the same results purely by coincidence:In [1]: import randomIn [2]: random.seed(32)In [3]: for roll in range(10): ...: print(random.randrange(1, 7), end=' ') ...: 1 2 2 3 6 2 4 1 6 1In [4] for roll in range(10): ...: print(random.randrange(1, 7), end=' ') ...: 1 3 5 3 1 5 6 4 3 5In [5] random.seed(32)In [6]: for roll in range(10): ...: print(random.randrange(1, 7), end=' ') ...: 1 2 2 3 6 2 4 1 6 1
Which of the following statements is false? In the top-down, stepwise refinement process for developing algorithms, each refinement represents another portion of the algorithm. In top-down, stepwise refinement, the top is a single statement that conveys the program's overall function but rarely conveys enough detail from which to write a program. The top specifies what should be done, but not how to implement it. In the refinement process, we decompose the top into a sequence of smaller tasks-a process sometimes called divide and conquer.
In the top-down, stepwise refinement process for developing algorithms, each refinement represents another portion of the algorithm.
Which of the following statements is false?
Interpreter programs, developed to execute high-level language programs directly, avoid the delay of compilation, and run faster than compiled programs.
Which of the following statements is false? Many scripts can be decomposed into initialization, processing and termination phases. The Style Guide for Python Code recommends placing a blank line above and below each control statement. Iteration is called definite iteration if the number of iterations is first known after the loop finishes executing. The following statement creates the variable grades and initializes it with a list of 10 integer grades.grades = [98, 76, 71, 87, 83, 90, 57, 79, 82, 94]
Iteration is called definite iteration if the number of iterations is first known after the loop finishes executing.
Which of the following statements is false? Python calls end a keyword argument, and end is a Python keyword. The end keyword argument is optional. If you do not include it, print uses a newline ('\n') by default. Built-in function print displays its argument(s), then moves the cursor to the next line. You can change this behavior with the argument end, as inprint(character, end=' ') Keyword arguments are sometimes called named arguments.
Keyword arguments are sometimes called named arguments.
Which of the following statements is false? The iterator is like a bookmark-it always knows where it is in the sequence, so it can return the next item when it's called upon to do so. Each sequence has an iterator. The for statement uses the iterator "behind the scenes" to get each consecutive item until there are no more to process. Lists are unordered and a list's items are mutable.
Lists are unordered and a list's items are mutable.
Which of the following statements about descriptive statistics is false? The range is the values starting with the minimum and ending with the maximum. The count is the number of values in a collection. Measures of dispersion (also called measures of variability), such as count, help determine how spread out values are. The minimum is the smallest value in a collection of values.
Measures of dispersion (also called measures of variability), such as count, help determine how spread out values are.
Which of the following statements is false? In IPython interactive mode, the line that begins with ----> shows the code that caused the exception. Python reports an exception with a traceback. Most exception names end with Exception. Dividing by zero with / or // is not allowed and results in an exception-an indication that a problem occurred.
Most exception names end with Exception.
Which of the following statements a), b) or c) is false? When a backslash (\) appears in a string, it's known as the escape character. All of the above statements are true Placing two backslashes back-to-back tells print to display a blank line. . The backslash and the character immediately following it form an escape sequence. For example, \n represents the newline character escape sequence, which tells print to move the output cursor to the next line.
Placing two backslashes back-to-back tells print to display a blank line.
Which of the following statements is false?
Programmers use the Python Standard Library and various other libraries to "reinvent the wheel."
________ is an informal English-like language for "thinking out" algorithms.
Pseudocode
Which of the following statements is false? Python allows you to split long code lines in parentheses without using continuation characters. Together, blank lines, space characters and tab characters are known as white space. Python ignores all white space. You use blank lines and space characters to make code easier to read.
Python ignores all white space.
Which of statements a), b) or c) is false? A variable name, such as x, is an identifier. Python is case insensitive, so number and Number are the same identifier despite the fact that one begins with a lowercase letter and the other begins with an uppercase letter. Each identifier may consist of letters, digits and underscores (_) but may not begin with a digit. All of the above statements are true.
Python is case insensitive, so number and Number are the same identifier despite the fact that one begins with a lowercase letter and the other begins with an uppercase letter.
The popular programming languages Python and ________ are the two most widely used data-science languages.
R
Which of the following statements is false? The placeholder {average} converts the variable average's value to a string representation, then replaces {average} with that replacement text. The following f-string inserts the value of average into a string:f'Class average is {average}' Replacement-text expressions in placeholders may contain values, variables or other expressions, such as calculations, but may not contain function calls. You specify where to insert values in an f-string by using placeholders delimited by curly braces ({ and }).
Replacement-text expressions in placeholders may contain values, variables or other expressions, such as calculations, but may not contain function calls.
Which of the following statements is false? The right side of the = symbol always executes first, then the result is assigned to the variable on the symbol's left side. The snippet in Part (a) is read, "total is assigned the value of x + y." The = symbol is the assignment operator. The following assignment statement adds the values of variables x and y and assigns the result to the variable total:total = x + y
The = symbol is the assignment operator.
Which of the following statements is false? A key programming goal is to avoid "reinventing the wheel." A package groups related modules. Every Python source-code (.py) file you create is a module. They're typically used to organize a large library's functionality into smaller subsets that are easier to maintain and can be imported separately for convenience. The Python Standard Library module money provides arithmetic capabilities for performing monetary calculations. A module is a file that groups related functions, data and classes.
The Python Standard Library module money provides arithmetic capabilities for performing monetary calculations.
Which of the following statements a), b) or c) is false? The built-in max and min functions also can receive an iterable, such as a list but not a string. The built-in max and min functions know how to determine the largest and smallest of their two or more arguments, respectively. All of the above statements are true. Using built-in functions or functions from the Python Standard Library's modules rather than writing your own can reduce development time and increase program reliability, portability and performance.
The built-in max and min functions also can receive an iterable, such as a list but not a string.
Which of the following statements is false? The diamond flowchart symbol has three flowlines emerging from it. One flowline emerging from the diamond flowchart symbol indicates the direction to follow when the condition in the symbol is True. This points to the action (or group of actions) that should execute. Another flowline emerging from the diamond flowchart symbol indicates the direction to follow when the condition is False. This skips the action (or group of actions). The decision (diamond) symbol contains a condition that can be either True or False.
The diamond flowchart symbol has three flowlines emerging from it.
Which of the following statements is false? Floor division (//) divides a numerator by a denominator, yielding the highest integer that's not greater than the result. The expression -13 // 4 evaluates to -3. The expression -13 / 4 evaluates to -3.25. True division (/) divides a numerator by a denominator and yields a floating-point number with a decimal point.
The expression -13 // 4 evaluates to -3.
Which of the following statements is false? In applications executed from a Terminal, Command Prompt or shell, type Ctrl+c or control + c (depending on your keyboard) to terminate an infinite loop. The while statement allows you to repeat one or more actions while a condition remains True. The following code sets product to the first power of 2 larger than 64:product = 2while product < 64:product = product * 2 Something in a while statement's suite must ensure that the condition eventually becomes False. Otherwise, a logic error called an infinite loop occurs.
The following code sets product to the first power of 2 larger than 64:product = 2while product < 64:product = product * 2
Which of the following statements is false? One of Python's most common iterable sequences is the list, which is a comma-separated collection of items enclosed in square brackets ([ and ]). The sequence to the right of the for statement's keyword in must be an iterable. An iterable is an object from which the for statement can take one item at a time until no more items remain. The following code totals five integers in a list:total = 0for number in [2, -3, 0, 17, 9]:total + number
The following code totals five integers in a list: total = 0 for number in [2, -3, 0, 17, 9]:total + number
Which of the following statements is false? The descriptive statistics mean, median and mode are measures of central tendency-each is a way of producing a single value that is in some sense typical of the others. The following session creates a list called grades, then uses the built-in sum and len functions to calculate the median "by hand"-sum calculates the total of the grades (397) and len returns the number of grades (5):In [1]: grades = [85, 93, 45, 89, 85]In [2]: sum(grades) / len(grades)Out[2]: 79.4 Like functions min and max, sum and len are both examples of functional-style programming reductions-they reduce a collection of values to a single value. The Python Standard Library's statistics module provides functions for calculating the mean, median and mode-these, too, are reductions.
The following session creates a list called grades, then uses the built-in sum and len functions to calculate the median "by hand"-sum calculates the total of the grades (397) and len returns the number of grades (5):In [1]: grades = [85, 93, 45, 89, 85]In [2]: sum(grades) / len(grades)Out[2]: 79.4
Which of the following statements is false? The following snippet produces the sequence 5 6 7 8 9.for number in range(5, 10): print(number, end=' ') The following snippet produces the sequence 0 2 4 6 8.for number in range(0, 10, 2): print(number, end=' ') The following snippet produces the sequence 10 8 6 4 2 0.for number in range(10, 0, -2):print(number, end=' ') Function range's one-argument version produces a sequence of consecutive integers from 0 up to, but not including, the argument's value.
The following snippet produces the sequence 10 8 6 4 2 0.for number in range(10, 0, -2): print(number, end=' ')
Which of the following statements is false? After the following snippet's assignment, the variable x refers to the integer object containing 7.x = 7 The following statement changes x's value:x + 10 The following statement changes x's value:x = x + 10 Assigning an object to a variable binds that variable's name to the object. You can then use the variable in your code to access the object's value.
The following statement changes x's value:x + 10
With regard to the following code segment: # process 10 students for student in range(10): # get one exam resultresult = int(input('Enter result (1=pass, 2=fail): '))if result == 1:passes = passes + 1else:failures = failures + 1which of the following statements is true? The if statement follows the for statement in sequence. The for statement is nested in the if statement. None of the above. Correct! The if statement is nested in the for statement.
The if statement is nested in the for statement.
Which of the following statements is false? Python provides three types of selection statements that execute code based on a condition-any expression that evaluates to either True or False. The if...elif...else statement is called a double-selection statement because it selects one of two different actions (or groups of actions). The if...else statement performs an action if a condition is True or performs a different action if the condition is False. Anywhere a single action can be placed, a group of actions can be placed.
The if...elif...else statement is called a double-selection statement because it selects one of two different actions (or groups of actions).
Which of the following statements is false? The indented lines after the colon (:) are the function's suite, which consists of an optional docstring followed by the statements that perform the function's task. Like variable identifiers, by convention function names should begin with a lowercase letter and in multiword names underscores should separate each word. The required parentheses in a function definition contain the function's parameter list-a comma-separated list of parameters representing the data that the function needs to perform its task. A function definition begins with the def keyword, followed by the function name, a set of parentheses and a colon (:).
The indented lines after the colon (:) are the function's suite, which consists of an optional docstring followed by the statements that perform the function's task.
Which of the following statements is false? The numpy module is typically imported withimport numpy as npy Typically, when importing a module, you should use import or import...as statements, then access the module through the module name or the abbreviation following the as keyword, respectively. This ensures that you do not accidentally import an identifier that conflicts with one in your code. import...as is frequently used to import Python libraries with convenient abbreviations, like stats for the statistics module. Sometimes it's helpful to import a module and use an abbreviation for it to simplify your code. The import statement's as clause allows you to specify the name used to reference the module's identifiers. For example, we can import the statistics module and access its mean function as follows:In [1]: import statistics as statsIn [2]: grades = [85, 93, 45, 87, 93]In [3]: stats.mean(grades)Out[3]: 80.6
The numpy module is typically imported with import numpy as npy
Which of the following statements is false? Parentheses in an expression are said to be redundant (unnecessary) if removing them yields the same result. Algebraic expressions must be typed in straight-line form using Python's operators. The following code multiplies 10 times the quantity 5 + 3, yielding the result 80:10 * (5 + 3) The parentheses in Part (b) above are redundant.
The parentheses in Part (b) above are redundant.
Which of the following statements is false? Sometimes the suites in an if...else statement assign different values to a variable, based on a condition, as in:grade = 87if grade >= 60:result = 'Passed'else:result = 'Failed' Correct Answer The parentheses in a conditional expression are required; otherwise, a syntax error occurs. You can replace if...else statements like the one above using a concise conditional expression:result = ('Passed' if grade >= 60 else 'Failed') All of the above statements are true.
The parentheses in a conditional expression are required; otherwise, a syntax error occurs.
Which of the following statements a), b) or c) is false? The following code calculates the population standard deviation with the statistics module's pstdev function:statistics.pstdev([1, 3, 4, 2, 6, 5, 3, 4, 5, 2]) The standard deviation is the square root of the variance, which tones down the effect of the outliers. All of the above statements are true. The smaller the variance and standard deviation are, the further the data values are from the mean and the greater overall dispersion (that is, spread) there is between the values and the mean.
The smaller the variance and standard deviation are, the further the data values are from the mean and the greater overall dispersion (that is, spread) there is between the values and the mean.
Which of the following statements a), b) or c) is false? The following code re-implements the for statement in Part (a) using an addition augmented assignment (+=) statement:for number in [1, 2, 3, 4, 5]: total += number The statement f = f ** 3 may be replaced by the more concise augmented assignment statementf *= 3. All of the above statements are true. Augmented assignments abbreviate assignment expressions in which the same variable name appears on the left and right of the assignment's =, as total does in:for number in [1, 2, 3, 4, 5]: total = total + number
The statement f = f ** 3 may be replaced by the more concise augmented assignment statementf *= 3.
Which of the following statements is false? You can use the remainder operator for applications such as determining whether one number is a multiple of another. The value of the following expression is 3:17 % 5 You can use the remainder operator to determine whether a number is odd or even. The value of the following expression is 0.5:7.5 % 3.5
The value of the following expression is 3: 17 % 5
Which of the following statements is false? The following snippet produces the integer sequence 0 1 2 3 4 5 6 7 8 9:for number in range(100):if number == 10:break print(number, end=' ') The following code snippet produces the sequence 0 1 2 3 4 5 5 6 7 8 9:for number in range(10): if number == 5: continue print(number, end=' ') Executing a break statement in a while or for immediately exits that statement. The while and for statements each have an optional else clause that executes only if the loop terminates normally.
The while and for statements each have an optional else clause that executes only if the loop terminates normally.
Which of the following statements a), b) or c) is false? To square a number, you can use the exponent 1/2 (that is, 0.5), as in:9 ** (1 / 2) All of the above statements are true. Python uses the asterisk (*) as the multiplication operator (e.g., 7 * 4). The exponentiation (**) operator raises one value to the power of another (e.g., 2 ** 10).
To square a number, you can use the exponent 1/2 (that is, 0.5), as in:9 ** (1 / 2)
Which of the following statements a), b) or c) is false?'' Using a keyword as an identifier causes a ValueError. A condition is a Boolean expression with the value True or False. All of the above statements are true. True and False are keywords-words that Python reserves for its language features.
Using a keyword as an identifier causes a ValueError.
Which of the following statements is false? Using the assignment symbol (=) instead of the equality operator (==) in an if statement's condition is a common logic error. Using == in place of = in an assignment statement can lead to subtle problems. Python requires you to indent the statements in suites. Incorrect indentation of the statements in a suite can cause errors.
Using the assignment symbol (=) instead of the equality operator (==) in an if statement's condition is a common logic error.
Which of the following statements is false? You also may enclose a string in double quotes ("), as in:print("Welcome to Python!")but Python programmers generally prefer single quotes. When print completes its task, it positions the screen cursor at the beginning of the next line by default. print does not display a string's quotes, though there is a way to display quotes in strings. When you evaluate expressions in interactive mode, the text that print displays is preceded by Out[] with a snippet number in the square brackets.
When you evaluate expressions in interactive mode, the text that print displays is preceded by Out[] with a snippet number in the square brackets.
Which of the following statements a), b) or c) is false? For a fatal logic error in a script, an exception occurs (such as a ZeroDivisionError from an attempt to divide by 0), so Python displays a traceback, then terminates the script. With a logic error, an IPython interactive session terminates. All of the above statements are true. A fatal error in interactive mode terminates only the current snippet. Then IPython waits for your next input.
With a logic error, an IPython interactive session terminates.
Which of the following statements is false? You may perform arithmetic between Decimals and floating-point numbers. You typically create a Decimal from a string. You may perform arithmetic between Decimals and integers. Decimals support the standard arithmetic operators +, -, *, /, //, ** and %, as well as the corresponding augmented assignments.
You may perform arithmetic between Decimals and floating-point numbers.
Which of the following statements is false? The if statementif not grade == -1: print('The next grade is', grade) also can be written as follows:if grade != -1: print('The next grade is', grade) You place the not operator before a condition to choose a path of execution if the original condition (without the not operator) is True. The Boolean not operator reverses the meaning of a condition-True becomes False and False becomes True. The not operator is a unary operator-it has only one operand.
You place the not operator before a condition to choose a path of execution if the original condition (without the not operator) is True.
You may spread a lengthy statement over several lines with the ________ continuation character. Correct! \ ^ % @
\
Which of the following statements is true? A.When you have many statements to execute as a group, you typically write them as a script stored in a file with the .py (short for Python) extension. B.The if statement uses a condition to decide whether to execute a statement (or a group of statements). C. IPython interactive mode is helpful for executing brief code snippets and seeing immediate results. D. All of the above statements are true
all of the above statements are true
A(n) ________ is the smallest data item in a computer. It can have the value 0 or 1.
bit
The most important flowchart symbol is the ________, which indicates that a decision is to be made, such as in an if statement.
diamond
The value 10.5 is a(n) ________ (that is, a number with a decimal point).
floating-point number
The applications-development methodology of ________ enables you to rapidly develop powerful software applications by combining (often free) complementary web services and other forms of information feeds.
mashups
Once Waze converts a spoken command to text, it must determine the correct action to perform, which requires:
natural language processing
With ________ software development, individuals and companies contribute their efforts in developing, maintaining and evolving software in exchange for the right to use that software for their own purposes, typically at no charge.
open-source
Information on secondary storage devices is ________ - it's preserved even when the computer's power is turned off.
persistent
Reworking programs to make them clearer and easier to maintain while preserving their correctness and functionality is called ________.
refactoring
The value of the expression '7' + '3' is the ________.
string '73'
A new class of objects can be created conveniently by inheritance-the new class (called the ________) starts with the characteristics of an existing class (called the ________), possibly customizing them and adding unique characteristics of its own.
subclass, superclass
Which Python Standard Library module do we use for performance analysis?
timeit
Various Python statements enable you to specify that the next statement to execute may be other than the next one in sequence. This is called ________ and is achieved with Python control statements.
transfer of control
________ is by far the world's most widely used desktop operating system.
windows