cis

¡Supera tus tareas y exámenes ahora con Quizwiz!

A dictionary key may consist of mutable data types. A. True B. False

B-dictionary key need to be immutable

quiz 1: Identify which of the following is NOT a Python expression. A. n + 3 B. zip = '97403' C. 42 D. math.pi

B-it's an assignment

The empty string assignment in the repeat() function is an example of the guardian pattern. A. True B. False

B-just initialization

Identify the correct result of the following statement. s1 = 'abc' s2 = 'xyz' list(zip(s1, s2)) A. [(0, 'a'), (1, 'b'), (2, 'c')] B. [('a', 'x'), ('b', 'y'), ('c', 'z')] C. 'abcxyz' D. 'axbycz'

B

Identify the name given to num in the Python code square(num). A. Function B. Argument C. Parameter D. Keyword

B

Identify the purpose of the isinstance() Python function. a. Exit a function b. Test the type of a variable C. Exit a loop D. Reverse a string

B

Identify the shape drawn by the following Python code. t.fd(100) # Assume t is a valid Turtle object t.lt(120) t.fd(100) t.lt(120) t.fd(100) A. Circle B. Triangle C. Square D. Line

B

Identify the syntax to declare an empty list in Python. A. my_list = list("empty") B. my_list = [] C. my_list = {} D. my_list = [:]

B

Identify the value of the variable x printed after complete execution of the following code. x = 10 def change_global(): x = 15 change_global() print(x) A. 0 B. 10 C. 15 D. None

B

Python fruitful functions with multiple return statements will generate a syntax error. A. True B. False

B

Closing a file does NOT reset the file object file pointer. A. True B. False

B - it does reset it

This code demonstrates an infinite loop. A. True B. False

B- goes until num=0

Identify the final value of word_cnt in the following Python code. s = "Peter Piper picked a peck of pickled peppers" word_cnt = 0 for chr in s: if chr == ' ': word_cnt = word_cnt + 1 A. 0 B. 7 C. 8 D. 10

B- just the spaces

Identify the output from the following Python function. def foo(): for i in range(4): print(i * 2, end = '') A. 0123 B. 0246 C. 1234 D. 2468

B-0 index

Dictionaries maintain items in sorted order. A. True B. False

b

Given d = dict(A = 'a', B = 'b'), select the Boolean result of 'a' in d. A. True B. False

b

Python lists are immutable. A. True b. False

b- MUTABLE means you can change you can't change the keys

The strip() method removes all leading, trailing and embedded white space. a. True b. False

b- no embedded

A tuple is simply another term for a list. A. True B. False

B

Composition is most effective when utilizing encapsulation and generalization. A. True B. False

A

Select the invalid Python relational operator? A. = B. == C. != D. <=

A

Identify the correct output of the following expression. 'xyz'[1] A. x B. y C. x D.xyz

B

Identify the correct output of the following expression. 'xyz'[1.0] A. x b. y c.z d. TypeError

D- can't do floats

2. Dictionary searches take about the same amount of time regardless of the number of dictionary items. A. True B. False

A

Identify the correct output from the following expression. '1234567890'[:2] A. 12 B. 21 C. 09 D. 98

A

Identify the existence or scope of variables in functions. A. Local B. Global C. Interactive D. Stack

A

Identify the mode of executing a Python program from the IDLE Editor. A. Interactive mode B. Script mode C. Execution mode D. A la mode

A

Identify the name given to adding and testing small amounts of code. A. Incremental development B. Refactoring C. Temporary variables D. Dead code

A

Identify the symbol used to indicate both gather and scatter. A. * B. % C. / D. ^

A

Identify the term given when an algorithm is applied to each element in a sequence. A. Map B. Filter C. Reduction D. Delimiter - splits keys

A

Identify the type of error encountered when a program will not execute. A. Syntax error-something wrong with the structure-individual set up is wrong B. Runtime error - never completes program (blank is not defined) C. Semantic error - program works but not how you want it to -- still prints but not what you want D. Function error

A

Lengthy conditional expressions may span multiple lines using parentheses. A. True B. False

A

The in operator can be used to search for one string within another string a. True b. False

A

Updating variables using increment and decrement do not require variable initialization. A. True B. False

A

The readline() method does NOT read any line ending characters. A. True B.False

A -reads anything unless you strip

What contractual term is given to a function's name, argument list, behavior, and return value (if any)? A. Interface B. Generalization C. Encapsulation D. Branch

A; description of all the functions doctrings describe the interface

A string is a sequence of alphabetic letters. A. True B. False

B

Common Python variable name for a file input object. A. input B. file C. fin D. t

C

Identify the correct syntax to escape a single quotation mark as a special character within a Python string. A. 'G'Day Mate!' B. "G'Day Mate!' C. 'G\nDay Mate!' D. 'G\'Day Mate!'

C

Identify the correct syntax to return the second dictionary value (underlined) from the following dictionary list. t = [{'A': 10}, {'B': 20}, {'C': 30}] A. t['B'] B. t['B'][1] C. t[1]['B'] D. t[2]['B']

C

Identify the data type returned by Python input statements. A. float B. integer C. string D. None

C

Identify the name given to the Python operator that combines strings. A. Combination operator B. Arithmetic operator C. Concatenation operator D. String operator

C

Identify the reason why a for loop is appropriate for the repeat() function rather than a while loop. A. While loop does not support concatenation B. Number of iterations is unknown C. Number of iterations is known D. Break statements are not allowed in functions

C

Identify the statistical term for a collection of counters. A. List B. Key-value pair C. Histogram D. Lookup

C

Identify the value of the my_list variable after complete execution of the following code. s = "what time is it" my_list = s.split() for item in my_list: item += "Noon!" a. "what time is it" b. ["what time is it"] c. ["what", "time", "is", "it"] d. ["noon", "noon", "noon", "noon"]

C

Identify which of the following is a valid Python floating point number. A. 'firstName' B. 3 C. 4.0 D. DEF

C

What alternate term is given to object functions used with the dot notation? A. Conditionals B. Modulus - % - gives remainder C. Methods D. Booleans

C

What term is given to the act of refining your code? A. Generalization B. Encapsulation C. Refactoring D. Composition

C

Identify the invalid Python variable name. A. _zip4 B. zip4 C. _4zip D. 4_zip

D- can't have number first

def repeat(data, count, spacer = '_'): result = ''; for i in range(count): result = result + data if i < count - 1: result = result + spacer return result Identify the correct output given the following function call. repeat('s', 3) a. 'sss' B. 's s s' C. 's_s_s' D. 's_s_s_'

C

Use the following code to answer questions 18 - 20 num = 7 count = 0 while num > 0: count = count + 1 num = num // 2 print('ABC'[::-1]) Identify the value of count AFTER the complete execution of the while loop. A. 0 B. 2 C. 3 D. 4

C - // rounds DOWN

Identify the output of the following Python code. price = 20.0 discount = 0.2 print(price * discount > 18.0 or price >= 20) A. 18 B. 20 C. True D. False

C- 4 is less that or equal to 20

10. Identify the correct tuple statement(s). A. tup = 1, 2, 3 B. tup = (1, 2, 3) C. tup = ((1, 2, 3)) D. All the above

D

12. Identify the example of a tuple assignment. A. x, y, z = 1, 2, 3 B. quot, rem = divmod(16, 5) C. Neither A or B D. Both A and B

D

Identify the Python exponential operator. A. Exp B. ^ C. * D. **

D

Identify the Python statement to immediately exit a loop. A. exit B. abs C. slice D. break

D

Identify the output of the print() function. A. ABC B. A C.C D, CBA

D

What Python element should always have a docstring? A. Conditional B. Variable C. Loop D. Function

D

Boolean functions make using the relational operator comparison unnecessary. A.True B.False

a

Identify the Python single line comment operator. A. # B. ''' C. // D. DEF

a

Identify the syntax to declare an empty dictionary in Python. A. d = dict("empty") B. d = [] C. d = {} D. d = [:]

c

Identify the correct output given the following function call. repeat('s', 1, '-') a. 'sss' b.'s_s_s' c. 's-s-s' d. 's'

d

Identify the correct term given to an object with more than one variable reference. a. Use case b. Equivalent c. List d. Alias

d


Conjuntos de estudio relacionados

Brit Lit: mastery test units 1-3 review

View Set

Communication and Customer Service in the Healthcare Office: Module 4: Maintaining Medical Records

View Set