CIT 1-10 Chapter Mid-Term Final

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

To avoid name collisions, variables in different functions' blocks must have different names. True OR False

False

Two objects can reside at the same memory address. True OR False

False

When defining a function, you cannot specify that a parameter has a default parameter value. True OR False

False

#2 NumPy determines the field width (in an array) based on the value that occupies the last position. True OR False

False, Based on the value that take up the most character spaces '140' and ' 2'

#3 findall

Finds every matching substring in a string and returns a list of the matching substrings.

#2 student_tuple = ('Amanda', 'Blue', [98.75.87]) Even though the tuple shown above is immutable, its list element is mutable. True OR False

True

#3 A base class exists in a hierarchical relationship with its subclasses. True OR False

True

#3 When Python processes an object at execution time, its type does not matter. As long as the object has the data attribute, property or method (with the appropriate parameters) you wish to access, the code will work. True OR False

True

#2 Replace *** with a set operator that will produce the results shown {1, 2, 4, 8, 16} *** {1, 4, 16, 64, 256} # {1,2,4,8,16,64,256}

| which is the Union (SLUG)

#2 Replace *** with a set operator that will produce the results shown {1, 2, 4, 8, 16} *** {1, 4, 16, 64, 256} # {1,4,16}

& which is the intersection

#2 Replace *** with a set operator that will produce the results shown {1, 2, 4, 8, 16} *** {1, 4, 16, 64, 256} # {2,8}

- which is the difference

#2 What values are actually displayed for 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]: ???

1. True 2. False

#2 For performance reasons, NumPy is written in the Java programming language and uses Java's data types. True OR False

False

#2 String keys are case insensitive. True OR False

False

#2 When you specify a slice and omit the starting index, 1 is assumed. So, the slice numbers[:6] is equivalent to the slice numbers[1:6]. If you omit the ending index, Python assumes the sequence's length. True OR False

False

#2 A Pandas Series is an enhanced two-dimensional array. True OR False

False

#2 When you use the Built-in functions sort it returns a new list containing the sorted elements of its argument sequence, the original sequence is unmodified. True OR False

False

#3 Base classes tend to be "more specific" and subclasses "more general." True OR False

False

#3 isalpha

Returns True if all characters in the string are alphabetic.

#2 What does this code do? temperatures = { 'Monday': [66, 70, 74], 'Tuesday': [50, 56, 64], 'Wednesday': [75, 80, 83], 'Thursday': [67, 74, 81] } for k, v in temperatures.items(): print(f'{k}: {sum(v)/len(v):.2f}') SHORT RESPONSE

This code calculates and displays the average temperature for the each day.

#2 A tuple's length cannot change during program execution. True OR False

True

#2 An equals (==) comparison evaluates to True if both dictionaries have the same key-value pairs, regardless of the order in which those pairs were added to each dictionary. True OR False

True

#3 It may seem that providing properties with both setters and getters has no benefit over accessing the data attributes directly, but there are subtle differences. - A getter seems to allow clients to read the data at will, but the getter can control the formatting of the data. -A setter can scrutinize attempts to modify the value of a data attribute to prevent the data from being set to an invalid value. True OR False

True

#3 With polymorphism, you simply send the same methods call to objects possible of many different types. Each object responds by "doing the right thing". So the same method call takes on many forms, hence the term "poly-morphism". True OR False

True

Using existing libraries helps you avoid "reinventing the wheel", thus leveraging your program-development efforts. True OR False

True

In which IPython interpreter mode do you enter small bits of Python code called snippets and immediately see their results? a.) interactive mode b.) script mode c.) program mode d.) none of the above

a.) interactive mode

#3 Python class ______ defines the special methods that are available for all Python objects. a.) object b.) special c.) class d.) root

a.) object

#2 Dictionary method ________ deletes the dictionary's key-value pairs. a.) clean b.) clear c.) delete d.) remove

b.) clear

#2 Lists may store ________ data, that is, data of many different types. a.) parallel b.) heterogeneous c.) homogeneous d.) none of the above

b.) heterogeneous

#3 Function _______ determines whether one class inherits from another. a.) isinstance b.) issubclass c.) isbaseclass d.) none of the above

b.) issubclass

A stack's items are removed in ___________ order. a.) first-in, first-out (FIFO) b.) last-in, first-out (LIFO) c.) first-in, last-out (FILO) d.) last-in, last-out (LILO)

b.) last-in, first-out (LIFO)

#2 The attribute ________ contains an array's number of dimensions and the attribute ________ contains a ________ specifying an array's dimensions: a.) dim, size, list b.) ndim, shape, tuple c.) dim size, tuple d.) ndim, shape, list

b.) ndim, shape, tuple

#3 A read-only property has ________. a.) only a setter b.) only a getter c.) a setter and a getter d.) neither a setter nor a getter

b.) only a getter

#2 Which of the following statements is false? a.) Python does not have a built-in stack type, but you can think of a stack as a constrained list. b.) You push using list method append, which adds a new element to the end of the list. c.) You pop using list method pop with no arguments, which removes and returns the item at the front of the list. d.) You can run out of memory if you keep pushing items faster than you pop them.

c.) You pop using list method pop with no arguments, which removes and returns the item at the front of the list.

#2 Consider the list color_names: color_names = ['orange', 'yellow', 'green'] Which of the following statements will insert red at the beginning of the list, so that you end up with ['red', 'orange', 'yellow', 'green']? a.) color_names.append('red') b.) color_names.insert('red') c.) color_names.insert(0, 'red') d.) color_names.insert(1, 'red')

c.) color_names.insert(0, 'red')

#3 Each new call you create becomes a new data type that can be used to create objects. This is one reason why Python is said to be a(n) ________ language. a.) dynamic typing b.) comprehensive c.) extensible d.) none of the above

c.) extensible

#3 Most object-oriented programming languages enable you to encapsulate (or hide) an object's data from the client code. Such data in these languages is said to be ________ data. a.) public b.) protected c.) private d.) none of the above

c.) private

The most popular database model is the ________ database, in which data is stored in simple tables. a.) network b.) graphical c.) relational d. hierarchical

c.) relational

Which of the following statements a), b) or c) is false? a.) A method is simply a function that you call on an object using the form object_name.method_name(arguments) b.) The following session calls the string object 's's lower and upper methods, which produce new strings containing all-lowercase and all-uppercase versions of the original string, leaving 's' unchanged: In [1]: s = 'Hello' In [2]: s.lower() # call lower method on string object s Out[2]: 'hello' In [3]: s.upper() Out[3]: 'HELLO' c.) After the preceding session, s contains 'HELLO'. d.) All of the above statements are true.

d.) After the preceding session, s contains 'HELLO'.

#3 Classes are new function types. True OR False

False

#3 The with statement implicitly releases resources when its suite finishes executing, however you still must include a close file type of statement. True OR False

False

Computing costs are rising dramatically, due to the increasing complexity of hardware and software technologies. True OR False

False

Today's fastest Internet speeds are on the order of millions of bits per second with billion-bits-per-second (gigabit) speeds already being tested. True OR False

False

#2 To identify a particular two-dimensional list element, we specify two indices—by convention, the first identifies the element's column, the second the element's row. True OR False

False, first -> row Second -> column

#3 istitle

Returns True if the first character of each word in the string is the only uppercase character in the word.

#3 endswith

Returns True if the string ends with the specified suffix.

#3 in operator

Returns True if the substring is in the string.

#3 replace

Returns a copy of the string with all occurrences of substring old replaced by new.

#3 lstrip

Returns a copy of the string with leading characters removed.

#3 swapcase

Returns a copy of the string with uppercase characters converted to lowercase and vice versa.

#3 split

Returns a list of words in the string, using the specified sep as the delimiter.

#3 count

Returns the number of occurrences of a substring.

#2 Most array operations execute significantly faster than corresponding list operations. True OR False

True

#2 NumPy does not display trailing 0x to the right of the decimal point in floating-point values. True OR False

True

#2 One of the features of a DataFrame is that it supports missing data. True OR False

True

#2 Dictionary keys must be unique. True OR False

True

#2 List comprehensions can replace many for statements that iterate over existing sequences and create new lists, such as: list1 = [ ] for item in range(1, 6): list1.append(item) We can accomplish the same task in a single line of code with a list comprehension: list2 = [item for item in range(1, 6)] True OR False

True

#2 Multiple keys can have the same value, such as two different inventory codes that have the same quantity in stock. True OR False

True

#2 Pandas displays a Series in two_column format with the indexes left aligned in the left column, and the values right aligned in the right column. True OR False

True

#2 The preferred mechanism for accessing an element's index and value is the built-in function enumerate, which receives an iterable and creates an iterator that, for each element, returns a tuple containing the element's index and value. True OR False

True

#3 Every statement in a class's suite is indented. True OR False

True

#3 Everything in Python is an object. True OR False

True

Executing a return statement without an expression terminates the function and implicitly returns the value None to the caller. When there's no return statement in a function, it implicitly returns the value None after executing the last statement in the function's block. True OR False

True

Importing a module's identifiers with a wildcard import can lead to subtle errors—it's considered a dangerous practice that you should avoid. (for example: from math import *) True OR False

True

Together, Bitcoin and Ethereum (another popular blockchain-based platform and cryptocurrency) consume more energy per year than Israel and almost as much as Greece. True OR False

True

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. True OR False

True

#2 Replace *** with a set operator that will produce the results shown {1, 2, 4, 8, 16} *** {1, 4, 16, 64, 256} # {2,8,64,256}

^ which is the symmetric difference

#3 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. a.) writing only b.) reading only c.) reading and writing d.) none of the above

b.) reading only

Reworking programs to make them clearer and easier to maintain while preserving their correctness and functionality is called ________. a.) design patterns b.) refactoring c.) editing d.) none of the above

b.) refactoring

What is the "ultimate goal" of the field of artificial intelligence? a.) Computers learning from massive amounts of data b.) Computer vision c.) Computers that perform intelligence tasks as well as humans d.) Self-driving cars

c.) Computers that perform intelligence tasks as well as humans

#3 The int function raises a ________ if you attempt to convert to an integer a string (like 'hello') that does not represent a number. a.) NameError b.) ConversionError c.) ValueError d.) none of the above

c.) Value-Error if correct but ValueError is not correct, should be Value-Error. test wants C though. the correct answer is non of the above.

#2 We use array method _________ to produce two-dimensional arrays from one-dimensional ranges. a.) shape b.) rectangularize c.) reshape d.) none of the above

c.) reshape

#2 Objects that "see" the data in other objects, rather than having their own copies of the data are called _________ objects. a.) subordinate b.) scene c.) view d.) aspect

c.) view

Python recently surpassed the programming language ________ as the most popular data-science programming language. a.) DSPL b.) Java c.) C++ d.) R

d.) R

Which of the following statements is false? a.) A key programming goal is to avoid "reinventing the wheel." b.) A module is a file that groups related functions, data, and classes. c.) 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. d.) The Python Standard Library module money provides arithmetic capabilities for performing monetary calculations.

d.) The Python Standard Library module money provides arithmetic capabilities for performing monetary calculations. Use the Decimal for fixed floating point value calculations.

#3 To create a Decimal object, we can write: value = Decimal('3.14159') This is known as a(n) ________ expression because it builds and initializes an object of the class. a.) builder b.) maker c.) assembler d.) constructor

d.) constructor

#2 Dictionary method _______ returns each key-value pair as a tuple. a.) add b.) keys c.) values d.) items

d.) items

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. a.) cloud computing b.) design patterns c.) proprietary computing d.) mashups

d.) mashups

#3 Properties are implemented as ________, so they may contain additional logic, such as specifying the format in which to return a data attribute's value or validating a new value before using it to modify a data attribute. a.) functions b.) suites c.) classes d.) methods

d.) methods


Kaugnay na mga set ng pag-aaral

Final Exam (Minus Test 1 Content)

View Set

Social Psychology Exam 3 Quiz Questions

View Set

AP Gov: Nominations and Campaigns (Unit 9)

View Set

Chapter 12: Leaders and leadership

View Set

Quiz 3 Chapter 3 "Business Ethics and Social Responsibility"

View Set