Python final part 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

two spaces to its left

"%6s" % "four" right-justifies the string by padding it with ____

A

"%6s" % "four" right-justifies the string by padding it with ____. a. two spaces to its left c. six spaces to its left b. two spaces to its right d. six spaces to its right

F

"A" < "B" evaluates to False.

What will be the return value of running the following function? chr(ord('T')+ 5)?

"Y"

F

"string" is an example of a data type in Python.

End-of-line comments begin with the ____ symbol

#

Python comes with _______, which helps to start from the point where we left off 'pause' 'break' 'halt' 'yield'

'yield'

You indicate a tuple literal in Python by enclosing its elements in ____.

( )

In order to create an empty set, ___________ is used, not a pair of empty braces, { }

()

You indicate a tuple literal in Python by enclosing its elements in ____.

()

In Python, ____ is the exponentiation operator

(**)

Parenthesize all of the subexpressions in the following expressions following operator precedence in Python. (a) var1 * 8 - var2 + 32 / var3 (b) var1 - 6 ** 4 * var2 ** 3

(a) (var1 * 8) - var2 + (32 / var3 ) (b) var1 - ((6 ** 4) * (var2 ** 3 )

What is the exact result of each of the following when evaluated? (a) 12 / 6.0 (b) 21 // 10 (c) 25 // 10.0

(a) 12 / 6.0 =2.0 (b) 21 // 10 =2 (c) 25 // 10.0 =2.0

Examine the following Python code: def avg(n1, n2, n3): #Line 1 sum = n1 + n2 + n3 #Line 2 return sum / 3.0 #Line 3 When calling this function, how many arguments would be passed to it? (a) 3 (b) Zero (c) 1 (d) 2 (e) Any of the above

(a) 3

Which of the following relational expressions evaluate to True? (a) 5 < 8 (b) '5' < '8' (c) '10' < '8' (d) 'Jake' < 'Brian'

(a) 5 < 8

What would the result of the turtle.setup(400, 500) be in turtle graphics? (a) A turtle screen of 400 pixels wide and 500 pixels high would be created. (b) A turtle screen of 500 pixels wide and 400 pixels high would be created. (c) A turtle screen of -400 to 400 pixels wide and -500 to 500 pixels high would be created. (d) A turtle screen of -500 to 500 pixels wide and -400 to 400 pixels high would be created. (e) None of the above

(a) A turtle screen of 400 pixels wide and 500 pixels high would be created.

The __doc__ extension in Python is used to (a) display the docstring of a program element (b) display all the docstrings in a given program (c) reassign the docstring of a program element (d) toggle the docstring of a program element on and off (e) returns True or False for determing if a given program element has a provided docstring

(a) display the docstring of a program element

Which of these is not a type of namespace in Python? (a) foreign Namesapce (b) built-In Namespace (c) global Namespace (d) local Namespace (e) these are all valid namespaces

(a) foreign Namesapce

Dictionaries in Python are (a) mutable (b) immutable (c) neither mutable nor immutable (d) mutable or immutable, depending on the situation (e) none of the above

(a) mutable

Which of the following is NOT an example of relative positioning? (a) the_turtle.setposition(100, 100) (b) the_turtle.forward(100) (c) the_turtle.left(90) (e) the_turtle.penup() the_turtle.hideturtle()

(a) the_turtle.setposition(100, 100)

For the following function, def elapsed_time(start_hr, start_mins, end_hr, end_mins) (a) Give an appropriate docstring specification, where function elapsed_time returns the total number of minutes between the provided start and end times. (b) GIve a print statement that displays the docstring for this function.

(a)'''returns the total number of minutes between the provided start and end times.''' (b)print(elapsed_time.__doc__)

Match the following. (a) function header ____ called for its returned value (b) function body (suite) ____ contains the function name and parameter list (c) value-returning ____ required in all value-returning functions function (d) non-value-returning ____ called for its side effects function (e) return statement ____ contains the functions instructions

(a)c (b)a (c)e (d)d (e)b

Assuming that two set of color names have been defined, color1 and color2, give the expression that would produce the names of the colors that are (a) in either color1 or color2 (b) in both color1 and color2 (c) in color1 but not in color2 (d) in either color1 or color2, but not both

(a)color1|color2 (b)color1&color2 (c)color1 - color2 (d)color1^color2

Match the following. (a) routine ____ value passed to a function when called (b) function ____ A named group of instructions performing some task (c) formal parameter ____ a function call, in which actual arguments are provided (d) actual argument ____ Python's version of a program routine (e) function invocation ____ an identifier provided in a function header

(a)d (b)a (c)e (d)b (e)c

Examine the following Python code: def runningSum(n): #Line 1 while n < 5: #Line 2 n = n + 1 #Line 3 # ---- main n = 1 #Line 4 runningSum(n) #Line 5 print(n) #Line 6 What will Line 6 print out? (a) 5 (b) 1 (c) 15 (d) 9 (e) 10

(b) 1

Examine the following Python code: def sumPos(nums): for k in range(0, len(nums)): if nums[k] < 0: nums[k] = 0 return sum(nums) # ---- main nums_1 = [5, -2, 9, 4, -6, 1] total = sumPos(nums_1) print('total = ', total) print(nums_1) What will the last line print out? (a) [5, -2, 9, 4, -6, 1] (b) [5, 0, 9, 4, 0, 1] (c) nums_1 (d) [19]

(b) [5, 0, 9, 4, 0, 1]

Which of the following contains the proper Python syntax for defining a dictionary? (a) fruitPrices = ['bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00] (b) fruitPrices = {'bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00} (c) monthlyIncome = [['March', 2000], ['April', 2300], ['May', 1900]] (d) firstFiveInts = {1, 2, 3, 4, 5} (e) None of the above

(b) fruitPrices = {'bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00}

The expression 4 + 3 is in (a) prefix Notation (b) infix Notation (c) postfix Notation

(b) infix Notation

Which of the following arithmetic expressions could potentially result in arithmetic overflow, where n,k are each assigned integer values, and q,r are each assigned floating-point values? (a) n * k (b) n ** k (c) n * q (d) r * q

(b) n ** k

The interface of a module is (a) an initial set of Python instructions of the module called once by any client (b) specification of the module providing information to any client (c) a common set of Python instructions in both the module and any of lts clients (d) a common specification in both the module and any client of its clients (e) a common set of values shared by both a module and its clients

(b) specification of the module providing information to any client

Which of the following relational expressions evaluate to True? (a) 5 <= 5 (b) 5 >= 5 (c) 5 == 5 (d) 5 != 5 (e) 5 != 10

(c) 5 == 5 (e) 5 != 10

Which of the following is not a standard exception in Python? (a) ImportError (b) IndexError (c) AssignmentError (d) TypeError (e) ValueError

(c) AssignmentError

Examine the following Python code: def avg(n1, n2, n3): #Line 1 sum = n1 + n2 + n3 #Line 2 return sum / 3.0 #Line 3 In Line 1, what is (n1, n2, n3) referred to as? (a) Function headers (b) Actual arguments (c) Parameter list (d) Logging variables (e) None of the above

(c) Parameter list

Broadly speaking, a module is (a) a design of specific functionality to be incorporated into a program (b) the implementation of specific functionality to be incorporated into a program (c) a design and/or implementation of specific functionality to be incorporated into a program (d) a function (e) a collection of functions

(c) a design and/or implementation of specific functionality to be incorporated into a program

After the following series of assignments are performed, list1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] list2 = list(list1) list2[0][0] = 10 (a) list1[0][0] will equal 1, and list2[0][0] will equal 10 (b) list1[0][0] will equal 10, and list2[0][0] will equal 1 (c) both list1[0][0] and list2[0][0] will equal 10 (d) an error will result (e) id(list1) will equal id(list2)

(c) both list1[0][0] and list2[0][0] will equal 10

The following line of code will: from math import factorial as simpFact (a) make every function from the math module available in a client program, but the function factorial will be renamed to simpFact. (b) import only the factorial function from the math module into client, which must be fully qualified when called. (c) import only the factorial function from the math module and integrate it into the namespace of the client as simpFact instead of factorial. (d) this is not proper Python code.

(c) import only the factorial function from the math module and integrate it into the namespace of the client as simpFact instead of factorial.

For variable n with the value 10, (a) n provides the reference value, and id(n) provides the dereferenced value 10 (b) n provides the value 10 and id(n) provides the value of the location of identifiers n in memory (c) n provides the value 10 and id(n) provides the location of the value 10 in memory (d) n and id(n) are two ways of obtaining the derefereneced value of 10 (e) n and id(n) are two ways of obtaining the reference value of 10

(c) n provides the value 10 and id(n) provides the location of the value 10 in memory

Assuming that the following function exists within a module to be imported into a client, how should the client treat this function? def __largerThan(num1, num2): """ Returns the larger of two numbers """ if num1 > num2: return num1 else: return num2 (a) the client can use this function at will as long as it imported. (b) this function is "private," even if a client imports its module, the function cannot be accessed. (c) this function is "private," the client can access it but should not. (d) the client should print this functions docstring before using it

(c) this function is "private," the client can access it but should not.

A docstring is (a) any Python string used to provide the specification of a program element (e.g., module) (b) any Python string delimited by double quotes providing the specification of a program element. (c) any Python string delimited by triple quotes providing the specification of a program element. (d) any Python string delimited by triple quotes given as the first line of a program element. (e) any triple quoted string in Python

(d) any Python string delimited by triple quotes given as the first line of a program element.

In Python, user-defined functions begin with a function header that starts with the keyword, (a) public (b) void (c) function (d) def (e) There are several keywords that can be used

(d) def

Which of the following is true of sets / frozensets in Python? (a) sets are immutable, and frozensets are mutable (b) sets are mutable and frozensets are both ordered data structures (c) sets are ordered mutable data structures, frozensets are unordered and immutable (d) sets are unordered mutable data structures, frozensets are unordered and immutable (e) none of the above

(d) sets are unordered mutable data structures, frozensets are unordered and immutable

Examine the following Python code: def avg(n1, n2, n3): #Line 1 sum = n1 + n2 + n3 #Line 2 return sum / 3.0 #Line 3 Which line/lines of code make up the suite (body) of the function? (a) Line 1 (b) Line 2 (c) Line 3 (d) Lines 1 and 2 (e) Lines 2 and 3

(e) Lines 2 and 3

After the following series of assignments are performed, list1 = [1, 2, 3, 4] list2 = list(list1) list1 = [5, 6, 7, 8] (a) list1 will no longer be referencing a list (b) list2 will no longer be referencing a list (c) variable list2 will be referencing the list [5, 6, 7, 8] (d) the list [1, 2, 3, 4] will no longer be referenced by variable list1 or list2 (e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]

(e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]

After the following series of assignments are performed, list1 = [1, 2, 3, 4] list2 = list1 list1 = [5, 6, 7, 8] (a) list1 will no longer be referencing a list (b) list2 will no longer be referencing a list (c) variable list2 will be referencing the list [5, 6, 7, 8] (d) the list [1, 2, 3, 4] will no longer be referenced by variable list1 or list2 (e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]

(e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]

Examine the following function header: def mortgagePayment(amount, rate, term): Which of the following calls to function mortgagePayment is invalid in Python? (a) mortgagePayment(350000, 5.5, 30) (b) mortgagePayment(amount=350000, rate=5.5, term=30) (c) mortgagePayment(350000, rate=5.5, term=30) (d) mortgagePayment(350000, term=30, rate=5.5) (e) mortgagePayment(rate=5.5, term=30, 350000)

(e) mortgagePayment(rate=5.5, term=30, 350000)

Which of the following returns the reference to the "default" turtle created as a result of a call to the setup method? (a) window.turtle() (b) window.getTurtle() (c) setup.getTurtle() (d) setup.getturtle() (e) turtle.getturtle()

(e) turtle.getturtle()

In Python, ________ is the exponentiation operator.

**

In Python, a ____ is the area of program text in which the name refers to a given value.

*name's scope module

You can join two or more strings to form a new string using the concatenation operator ____.

+

Know all of the mathematical operators and how they are used.

-x, x+y, x-y, x*y, x/y, x//y, x%y, x**y

Examine the following code: def myMoney(cashOnHand=0, debt=0): #Line 1 return cashOnHand - debt #Line 2 # ---- main print(myMoney()) #Line 3 print(myMoney(50)) #Line 4 print(myMoney(120, 50)) #Line 5 print(myMoney(debt=250, cashOnHand=25)) #Line 6 What will the output of this code be?

0 50 70 -100

range(<upper>) returns a list containing the integers in the range ____.

0 through upper - 1

F (1,500-1500)

1,500 is a valid integer literal in Python.

Examine the following Python code list1 = [1, 2, 3, 4, 5] list2 = list1 list1.append(6) list2.append(7) for i in list1: print(i, end = '') print() for i in list2: print(i, end = '') What will this code output? Explain

1234567 and 1234567 because list2 is pointing to the same object in memory as list 1 so whenever one changes the other does too

Which of the following is NOT a valid name that can be used for a variable?

1ending

What is the total number of distinct values in the ASCII set?

256

D

28. A ____ organizes data values by association with other data values rather than by sequential position. a. list c. data structure b. string d. dictionary

B

29. A list is a sequence of data values called ____. a. indexes c. iterators b. items d. components

____ is not a valid list in Python.

2:4

Which of the following literals would be considered a float type in Python?

3.14

A

31. ____ returns the number of elements in the list. a. len(L) c. length(L) b. siz(L) d. size(L)

A

35. The L.____() method of the list type removes and returns the element at the end of the list. a. pop c. get b. remove d. append

A

36. The L.____(index) method of the list type removes and returns the element at index. a. pop c. get b. remove d. append

B

37. Mutable objects have some methods devoted entirely to modifying the internal state of the object. Such methods are called ____. a. accessors c. modifiers b. mutators d. procedures

F

4 != 4 evaluates to True.

C

50. You can use the dictionary method ____ to access a list of the dictionary's entries. a. elements() c. items() b. entries() d. list()

A try, except, or finally block must all be followed by a ____ before stating individual commands. ( ) ; : { }

:

F

A Python dictionary is written as a sequence of key/value pairs separated by commas. These pairs are sometimes called indexes.

If the program works correctly with ____, we can assume that it will work correctly with larger values.

A TEST SUITE

D

A __ is the way a value of a data type looks to a programmer: a) class b) data structure c) data type d) literal

list

A ____ allows the programmer to manipulate a sequence of data values of any types.

A

A ____ allows the programmer to manipulate a sequence of data values of any types. a. list b. string c. data structure d. dictionary

A

A ____ allows the programmer to manipulate a sequence of data values of any types. a. list c. data structure b. string d. dictionary

A

A ____ must follow the else in an if-else statement. a. : c. , b. ; d. {

dictionary

A ____ organizes data values by association with other data values rather than by sequential position

D

A ____ organizes data values by association with other data values rather than by sequential position. a. list b. string c. data structure d. dictionary

D

A ____ organizes information by association. a. string c. list b. tuple d. dictionary

List

A ______ allows the programmer to manipulate a sequence of data values for any types.

:

A _______ must follow the else in an if-else statement.

object

A compound data type that is often used to model a thing or concept in the real world. It bundles together the data and the operations that are relevant for that kind of data. Instance and object are used interchangeably.

T

A condition expresses a hypothesis about the state of its world at that point in time.

What is the difference between a control statement and a control structure?

A control statement is a statement that determines the control flow of a set of instructions. A control structure is a set of instructions and the control statements controlling their execution.

running a set of statements a predictable number of times

A for loop is convenient for

true

A function can be defined in a Python shell, but it is more convenient to define it in an IDLE window, where it can be saved to a file

T

A function can be defined in a Python shell, but it is more convenient to define it in an IDLE window, where it can be saved to a file.

object-oriented language

A language that provides features, such as user-defined classes and inheritance, that facilitate object-oriented programming.

items

A list is a sequence of data values called ____

B

A list is a sequence of data values called ____. a. indexes b. items c. iterators d. components

F

A list is a sequence of data values called indexes.

F (they are called items or elements)

A list is a sequence of data values called indexes.

true

A list is immutable

F

A list is immutable.

F (a list is mutable. A tuple is immutable.)

A list is immutable.

T

A lookup table is a type of dictionary.

true

A method is always called with a given data value called an object, which is placed before the method name in the call.

A

A modern____organizes the monitor screen around the metaphor of a desktop, with windows containing icons:a)GUI, b)CLI, c)terminal-based interface, d)applications software

object-oriented programming

A powerful style of programming in which data and the operations that manipulate it are organized into classes and methods.

What is meant by a "straight-line" program?

A program consisting of only sequential control

F (machine)

A program stored in computer memory must be represented in binary digits, which is also known as ascii code.

T

A programmer typically starts by writing high-level language statements in a text editor.

What statement accurately describes what a semantic error is?

A semantic error happens when an expression attempts to perform operations between incompatible data types.

T

A semantic error is detected when the action which an expression describes cannot be carried out, even though that expression is syntactically correct.

initializer method

A special method in Python (called __init__) that is invoked automatically to set a newly-created object's attributes to their initial (factory-default) state.

T

A variable associates a name with a value making it easy to remember and use the value later in a program.

caesar

A very simple encryption method that has been in use for thousands of years is called a(n) ____ cipher.

T

A while loop can be used for a count-controlled loop.

C

A(n) __ is a piece of program text that the interpreter ignores but that provides useful documentation to programmers: a) literal b) instance c) comment d) documentation

A

A(n) __ program produces the expected output for any legitimate input: a) correct b) appropriate c) efficient d) logical

D

A(n) ____ is a type of sequence that resembles a list, except that, unlike a list, it is immutable. a. index b. class c. string d. tuple

D

A(n) ____ is a type of sequence that resembles a list, except that, unlike a list, it is immutable. a. index c. string b. class d. tuple

parameter

A(n) ____ is the name used in the function definition for an argument that is passed to the function when it is called.

B

A(n) ____ is the name used in the function definition for an argument that is passed to the function when it is called. a. variable c. class b. parameter d. object

algorithm

A(n) _____ is a general method for solving a class of problems

Arithmetic

A(n) ______ expression consists of operands and operators combined in a manner that is already familiar to you from learning algebra.

Comment

A(n) ______ is a piece of program text that the interpreter ignores but that provides useful documentation to programmers.

The result of evaluating 45%0 is ____

AN ERROR

In the ____ phase of the waterfall model, the programmers determine what the program will do.

ANALYSIS

A(n) ____ expression consists of operands and operators combined in a manner that is already familiar to you from learning algebra.

ARITHMETIC

C

A____takes a set of machine language instructions as input and loads them into the appropriate memory locations:a)compiler, b)linker, c)loader, d)primary

pseudocode

Algorithms are more often written in a somewhat stylized version of English called ____.

B

Algorithms are more often written in a somewhat stylized version of English called: a) Byte code b) Pseudocode c) Machine code d) Boolean code

Which of the following is a Python built-in exception? EOFError KeyError SystemExit All of the above

All of the above

T

Although a list's elements are always ordered by position, it is possible to impose a natural ordering on them as well.

T

Although the while loop can be complicated to write correctly, it is possible to simplify its structure and thus improve its readability.

F

An Identity function usually tests its argument for the presence or absence of some property.

finite

An algorithm consists of a(n) ____ number of instructions

A

An algorithm consists of a(n)____ number of instructions: a)finite, b)infinite, c)predefined, d)undefined

T

An algorithm describes a process that ends with a solution to a problem.

F (eventually)

An algorithm describes a process that may or may not halt after arriving at a solution to a problem.

T

An algorithm solves a general class of problems.

A

An example of conditional iteration is when a program's input loop accepts values until the user enters a special value or a ____ terminates the input. a. sentinel c. variable b. literal d. marker

T

An important part of any operating system is its file system, which allows human users to organize their data and programs in permanent storage.

T

Ancient mathematicians developed the first algorithms.

C

Another name for a logic error is a __ error: a) Syntax b) Debugging c) Design d) Pseudocode

design

Another name for a logic error is a ____ error.

Design

Another name for a logic error is a ______ error.

T

Anytime you foresee using a list whose structure will not change, you can, and should, use a tuple instead.

parameters

Arguments are also known as ____.

92804574

Assume that the input file "input.csv" looks like the following: Sam,92 Zoe,80 Ted,45 Sue,74 What is the output of the following code? x = "" file = open("input.csv", "r") line = file.readline() while (len(line) > 0): parts = line.strip().split(",") x += parts[1] line = file.readline() print(x) file.close()

Examine the following Python code: def compare(num1, num2): if num1 > num 2: return num1 else: return num2 # ---- main num1 = int(input('Enter a number')) num2 = int(input('Enter a number')) print(compare(num2, num1), 'is the bigger number')) The formal parameters in the function definition are ordered num1, num2, but in the function call, the actual arguments are ordered num2, num1. This is neither a syntactic nor a semantic error. Explain why.

Because the function will work regardless due to the if else statements.

How does the int function convert a float to an int?

By removing the fractional value of the number.

T

By the mid 1980s, the Arpanet had grown into what we now call the Internet, connecting computers owned by large institutions, small organizations, and individuals all over the world.a

C

CDs and DVDs are an example of____storage media:a)semiconductor, b)magnetic, c)optical, d)primary

A(n) ____ is a piece of program text that the interpreter ignores but that provides useful documentation to programmers.

COMMENT

A(n) ____ program produces the expected output for any legitimate input.

CORRECT

In the ____ phase of the waterfall model, the programmers receive a broad statement of a problem that is potentially amenable to a computerized solution.

CUSTOMER REQUEST

____ took the concept of a programmable computer a step further by designing a model of a machine that, conceptually, bore a striking resemblance to a modern general-purpose computer.

Charles Babbage

___________ allow sequences to be built from other sequences. *

Comprehensions

T

Computer science focuses on a broad set of interrelated ideas.

B

Computers can communicate with the external world through various____that connect them to networks and to other devices such as handheld music players and digital cameras:a)facilities, b)ports, c)racks, d)slots

T

Conditional iteration requires that a condition be tested within the loop to determine whether the loop should continue.

What is the term for the order that instructions are executed in a program?

Control flow

What is the term for a statement that determines the control flow of a set of instructions?

Control statement

To quit the Python shell, you can either select the window's close box or press the ____ key combination.

Control+D

10000101

Convert the following number from decimal to binary, and enter your answer in binary without any leading zeroes: 133

In programming, a ____ consists of a set of values and a set of operations that can be performed on those values.

DATA TYPE

Another name for a logic error is a ____ error.

DESIGN

In the ____ phase of the waterfall model, the programmers determine how the program will do its task.

DESIGN

Assuming that dictionary spanish_days from the question above has been defined, give an instruction that uses spanish_days to display "The word for Monday in Spanish is Lunes"

Day='Monday' print("the word for", day, "in Spanish is", Spanish_days[day]

Assuming the dictionary spanish_days from the question above has been defined, and that variable day contains one of 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' and 'Sunday'. Give an instructions that displays "The word for english_dayname in Spanish is Spanish_dayname"

Day='Monday' print("the word for", day, "in Spanish is", Spanish_days[day]

Write a function called getNum(start, end) that is passed the starting and ending values of a range of integers, prompts the user to enter an integer in the specified range, and returns the integer entered. The function should throw a ValueError exception if the entered number is not within the required range.

Def getNum(start, end): Num=int(input("Enter a number between", start, "and", end:) If num < start or num > end: Raise ValueError ('Not within range') Return num

Which of the following exceptions is raised when the input() functions hits end-of-file condition. EOFError MemoryError AsertionError TypeError

EOFError

T

Each individual instruction in an algorithm is well defined.

T

Each item in a list has a unique index that specifies its position.

B

Early in the nineteenth century, ____designed and constructed a machine that automated the process of weaving:a)George Boole, b)Joseph Jacquard, c)Herman Hollerith, d)Charles Babbage

#

End of line comments begin with the _____ symbol.

#

End-of-line comments begin with the ____ symbol.

D

Errors to rule out during testing the while loop include an incorrectly initialized loop control variable, failure to update this variable correctly within the loop, and failure to test it correctly in the ____ condition. a. count c. exit b. sentinel d. continuation

F (left-right)

Exponentiation and assignment operations are right associative

In evaluating the precedence rules used by Python, what statement is accurate?

Exponentiation has the highest precedence.

T

Expressions provide an easy way to perform operations on data values to produce other data values.

In Python, int, long, and ____ are called numeric data types.

FLOAT

__________ was considered ideal for numerical and scientific applications.

FORTRAN

"A" < "B" evaluates to False

False

(T/F) 1,500 is a valid integer literal in Python

False

(T/F) A program stored in computer memory must be represented in binary digits, which is also known as ascii code.

False

(T/F) Exponentiation and assignment operations are left associative.

False

(T/F) In Python, \b is a escape sequence that represents a horizontal tab.

False

(T/F) In Python, the programmer can force the output of a value by using the cout statement.

False

(T/F) In the maintenance phase of the waterfall model, the parts of a program are brought together into a smoothly functioning whole, usually not an easy task.

False

(T/F) Informally, a computing agent is like a recipe.

False

(T/F) Information is stored as patterns of bytes (1s and 0s)

False

(T/F) Moore's Law states that the processing speed and storage capacity of hardware will increase and its coset will decrease by approximately a factor of 3 every 18 months.

False

(T/F) Python is a loosely typed programming language.

False

(T/F) String is an example of a data type in Python.

False

(T/F) Text processing is by far the least common application of computing.

False

(T/F) The cost of developing software is spread equally over the phases.

False

(T/F) The development of the transistor in the early 1960s allowed computer engineers to build ever smaller, faster, and less expensive computer hardware components.

False

(T/F) When writing Python programs, you should use a .pyt extension.

False

1,500 is a valid integer literal in Python

False

1,500 is a valid integer literal in Python.

False

4 != 4 evaluates to True

False

A Python function cannot under normal circumstances reference a module variable for its value.

False

A module behaves like a function, but has a slightly different syntax.

False

A recursive function must contain at least one repetition statement.

False

Comprehensions can not be used to generate the Cartesian product of two sets *

False

Data can be output to a text file using a(n) output object.

False

Exponentiation and assignment operations are left associative

False

Exponentiation and assignment operations are left associative.

False

For data that are owned by individual objects, you must use class variables.

False

For the most part, off by one errors result when the programmer incorrectly specifies the lower bound of the loop

False

If the parenthesized parent class name is omitted from the class definition, the new class is automatically made a subclass of self.

False

In Python % is the exponentiation operator

False

In Python \b is an escape sequence that represents a horizontal tab

False

In Python, % is the exponentiation operator.

False

In Python, = means equals, whereas == means assignment

False

In Python, \b is a escape sequence that represents a horizontal tab.

False

In Python, a floating-point number must be written using scientific notation

False

In Python, a floating-point number must be written using scientific notation.

False

In the maintenance phase if the waterfall model, the parts of a program are brought together into a smoothly functioning whole, usually not an easy task

False

In the maintenance phase of the waterfall model, the parts of a program are brought together into a smoothly functioning whole, usually not an easy task.

False

Inheritance allows several different classes to use the same general method names.

False

Like with an infinite loop, an infinite recursion eventually halts execution with an error message.

False

Loop statements allow a computer to make choices

False

Most recursive functions expect no arguments.

False

Newer versions of Python (Python 3) comprehensions can not be used with dictionary and sets. *

False

Python includes many useful functions, which are organized in libraries of code called classes

False

Python is a loosely typed programming lanugage

False

Text processing is by far the least common application of computing

False

Text processing is by far the least common application of computing.

False

The + operator allows you to build a string by repeating another string a given number of times

False

The + operator allows you to build a string by repeating another string a given number of times.

False

The Boolean data type is named for the twentieth century British mathematician George Boole

False

The augmented assignment operations have a higher precedence than the standard assignment operation

False

The cost of developing software is spread equally over the phases

False

The cost of developing software is spread equally over the phases.

False

The design phase of the waterfall model is also called the coding phase

False

The design phase of the waterfall model is also called the coding phase.

False

The modulus operator has the highest precedence and is evaluated first

False

The modulus operator has the highest precedence and is evaluated first.

False

The not operator has a lower precedence than the and and or operators

False

The or operator returns True if and only if both of its operands are true, and returns False otherwise

False

The process of sending a result back to another part of the program is known as pushing a value

False

The scope of an instance variable is the entire module.

False

The simplest form of selection of selection is the if-else statement

False

The statements in the loop body need not be indented and aligned in the same column.

False

The statements within a while loop can execute one or more times.

False

The while loop is also called a sentinel-control loop, because its condition is tested at the top of the loop.

False

True of False? All functions are designed to return a value.

False

True or False? As long as a function is defined somewhere in a program, it can be called anywhere within the program

False

True or False? Calls to non-value-returning functions cannot be used anywhere that a statement is expected.

False

True or False? Functions must contain at least one formal parameter.

False

When using the open function to open a file for output (i.e., using 'w' as the mode string), if the file does not exist, Python raises an error.

False

string is an example of a data type in Python

False

string is an example of a data type in Python.

False

'_______' blocks get executed automatically, and are mostly used to release external resources. Finally Try Catch Except

Finally

Give Python code that, for any state of the U.S. assigned to variable state_name, displays the name ensuring that the first letter is displayed capitalized.

First_letter=state_name[0] Other_letters=state_name[1:len(state_name)] first_letter=first_letter.upper() Print(first_letter+other_letters)

A

Flash memory sticks are an example of____storage media:a)semiconductor, b)magnetic, c)optical, d)primary

In Python, what data type is used to represent real numbers between -10^308 and 10^308 with 16 digits of precision?

Float

F

For the most part, off-by-one errors result when the programmer incorrectly specifies the lower bound of the loop.

_______ developed a system of logic which consisted of a pair of values, TRUE and FALSE, and a set of three primitive operations on these values, AND, OR, and NOT.

George Boole

A modern ________ organizes the monitor screen around the metaphor of a desktop, with windows containing icons for folders, files, and applications.

Graphical User Interface (GUI)

T

Guido van Rossum invented the Python programming language in the early 1990s.

___________ consists of the physical devices required to execute algorithms.

Hardware

___________ developed a machine that automated data processing for the U.S. Census.

Herman Hollerith

_________ programming languages resemble English and allow the author to express algorithms in a form that other people can understand.

High-level

When opening a file for reading, an error that may occur is _____________________________

I/O error

T

IN the 1960s, batch processing sometimes caused a programmer to wait days for results, including error messages.

For variable current_month (equal to 'January' or 'February' ot 'March', etc.) write an if statement that assigns variable fall_season to True if the value of current_month is either 'September', 'October' or 'November'; otherwise, fall_season should have the value False.

If (current_month=='September')or(current_month=='October')or(current_month=='November'): fall_season=True else: fall_season=False

For a variable named with integer value, give an if statement that displays "valid value" if the value of num is between 1 and 100, inclusive, and displays "invalid value" otherwise.

If (num>=1) and (num<=100): print('valid value') else: print('invalid value')

T

If Python expression is well formed, the interpreter translates it to an equivalent form in a low-level language.

Give Python code that display "Valid SSN" if the string assigned to variable SSN is a valid social security number, and displays "Invalid SSN" otherwise. A social security number is valid if it contains exactly nine digits, and no other characters

If SSN.isdigit() == True and len(SSN) == 9: Print("Valid SSN") Else: Print("Invalid SSN")

C

If a function contains no return statement, Python transfers control to the caller after the last statement in the function's body is executed, and the special value ____ is automatically returned. a. '\n' c. None b. EOF d. Null

None

If a function contains no return statement, python transfers control to the caller after the last statement in the function's body is executed, and special value _____ is automatically returned.

T

If pop is used with just one argument and this key is absent from the dictionary, Python raises an error.

A

If the existence of a key is uncertain, the programmer can test for it using the dictionary method ____. a. has_key c. hasKey b. haskey d. has-key

D

If the program works correctly with __, we can assume that it will work correctly with larger values: a) input values b) an abstraction c) a syntax error d) a test suite

T

In 1984, Apple Computer brought forth the Macintosh, the first successful mass-produced personal computer with a graphical user interface.

F (%-**)

In Python, % is the exponentiation operator.

false

In Python, = means equals, whereas == means assignment.

F (\b-\t)

In Python, \b is an escape sequence that represents a horizontal tab.

D

In Python, a ____ associates a set of keys with data values. a. string c. list b. tuple d. dictionary

:

In Python, a ____ ends the loop header

A

In Python, a ____ ends the loop header. a. : c. , b. ; d. ->

F (add or decimal notation)

In Python, a floating-point number must be written using scientific notation.

D

In Python, a string literal is a sequence of characters enclosed in __: a) square brackets b) single quotation marks c) double quotation marks d) single or double quotation marks

T

In Python, functions and other resources are coded in components called modules.

B

In Python, int, long, and __ are called numeric data types: a) str b) float c) dec d) decimal

float

In Python, int, long, and ____ are called numeric data types.

F (print)

In Python, the programmer can force the output of a value by using the cout statement.

Str

In Python, the values of most of the data types can be converted to strings by using the _______ function.

B

In Python, you can write a print statement that includes two or more expressions separated by____:a)periods, b)commas, c)colons, d)semicolons

B

In ____ format, numbers and other information are aligned in columns that can be either left-justified or right-justified. a. range c. column b. tabular d. row-order

C

In a computer, the____devices include a keyboard, mouse, and microphone: a)memory, b)CPU, c)input, d)output

F

In a dictionary, a -> separates a key and its value.

B

In a loop each repetition of the action is known as a pass or a ___: a) round b) initialization c) header d) banner

C

In carrying out the instructions of any algorithm, the computing agent starts with some given information known as____: a)data, b)variables, c)input, d)output

D

In carrying out the instructions of any algorithm, the computing agent transforms some given information according to well-defined rules and produces new information known as____:a)data, b)variables, c)input, d)output

A

In computer science, data structures organized by association are sometimes called ____. a. tables c. stacks b. lists d. queues

T

In general, a variable name must begin with either a letter or an underscore (_).

C

In its early days, ____was primarily used for lab experiments in an area of research known as artificial intelligence:a)COBOL, b)machine code, c)LISP, d)FORTRAN

C

In programming, a __ consists of a set of values and a set of operations that can be formed on those values: a) class b) data structure c) data type d) literal

F

In python, = means equals, whereas == means assignment.

:

In python, a ______ ends the loop header.

Float

In python, int, long, and _____ are called numeric data types.

abstraction

In science or any other area of enquiry, a(n) ____ allows human beings to reduce complex ideas or entities to simpler ones.

A

In science or any other area of enquiry, a(n)____allows human beings to reduce complex ideas or entities to simpler ones.a)abstraction, b)algorithm, c)module, d)compiler

F

In scripts that include the definitions of several cooperating functions, it is often useful to define a special function named init that serves as the entry point for the script.

F (Alan Turing)

In the 1930s, the mathematician Blaise Pascal explored the theoretical foundations and limits of algorithms and computation.

analysis

In the ____ phase of the waterfall model, the programmers determine what the program will do.

F (1950s)

In the early 1940s, computer scientists realized that a symbolic notation could be used instead of machine code, and the first assembly languages appeared.

B

In the early 1980s, a college dropout name Bill Gates and his partner Paul Allen built their own operation system software, which they called____:a)LISP, b)Windows, c)MS-DOS, d)Linux

short-circuit

In the expression (A or B), if A is true, then so is the expression, and there is no need to evaluate B. This approach, in which evaluation stops as soon as possible, is called ____ evaluation.

C

In the expression (A or B), if A is true, then so is the expression, and there is no need to evaluate B. This approach, in which evaluation stops as soon as possible, is called ____ evaluation. a. Boolean c. short-circuit b. strongly-typed d. lazy

A

In the modern world of computers, information is also commonly referred to as____: a)data, b)bits, c)input, d)records

What statement accurately describes the analysis phase of the waterfall model?

In this phase, the programmers determine what the program will do.

F (algorithm)

Informally, a computing agent is like a recipe.

F (binary digits)

Information is stored as patterns of bytes (1s and 0s).

Provide Python code that prompts the user for the file name of the form filename.txt of a text file, opens the file, and displays each of the names on the screen, one per screen line

Input_file=input('Enter file name:') Open(input_file,'r') For line in input_file: Print(input_file.readline())

Provide Python code that prompts the user for the file name of the form filename.txt of a text file, opens the file, and writes the contents of the file to a new file name filename-2.txt.

Input_file=input('Enter file name:') Open(input_file,'r') Output_file=('filename-2.txt','w') For line in input_file: Output_file.write(line)

Provide Python code that opens a file named names.txt, in which each line of the file contains a friends name in the form firstname lastname, and displays each of the names on the screen, one per screen line

Input_file=open(names.txt,'r') For line in input_file: Print(input_file.readline())

What special character does the &#39;\b&#39; escape sequence generate?

It produces a backspace special character, which performs the same function as the backspace key.

In Python, what does the &quot;%&quot; operator do in the expression 6 % 4?

It returns a remainder or modulus.

Which form of control flow repeatedly executes a set of instructions?

Iterative

Early in the nineteenth century, ______________ designed and constructed a machine that automated the process of weaving.

Joseph Jacquard

In its early days, _________ was used primarily for laboratory experiments in an area of research known as artificial intelligence.

LISP

A ____ is the way a value of a data type looks to a programmer

LITERAL

T

Lists of integers can be built using the range function.

F

Loop statements allow a computer to make choices.

D

Loops that count through a range of numbers are also called ____ loops. a. range-delimited c. iterative b. numbering d. count-controlled

During the ____ phase of the waterfall model, requirements change, errors are detected, and minor or major modifications are made

MAINTENANCE

In the early 1980s, a college dropout named Bill Gates and his partner Paul Allen built their own operating system software, which they called ____.

MS-DOS

T

Magnetic storage media, such as tapes and hard disks, allow bit patterns to be stored as patterns on a magnetic field.

F (2)

Moore's Law states that the processing speed and storage capacity of hardware will increase and its cost will decrease by approximately a factor of *3* every 18 months.

B

Mutable objects have some methods devoted entirely to modifying the internal state of the object. Such methods are called ____. a. accessors b. mutators c. modifiers d. procedures

Which of the following exceptions is raised when a variable is not found in local or global scope? OSError KeyError AssertionError NameError

NameError

steps in creating an object

Naming, data member/ characteristics of object, setters/getters, mutators

Which of the following exceptions is raised by abstract methods? NotImplementedError ReferenceError EOFError IndexError

NotImplementedError

A

Off-by-one errors in loops are ____ errors. a. logic c. semantic b. syntax d. debugging

Arguments are also known as _____

PARAMETERS

Algorithms are more often written in a somewhat stylized version of English called ____.

PSEUDOCODE

methods

Python includes a set of string operations called ______ that make tasks like counting the words in a single sentence easy.

F (classes-modules)

Python includes many useful functions, which are organized in libraries of code called classes.

F (loosely-strongly)

Python is a loosely typed programming language.

interpreted

Python is a(n) ____ language.

C

Python is a(n)____language:a)functional, b)assembly, c)interpreted, d)compiled

A

Python's __ function returns a string's length when it is passed a string: a) len b) length c) siz d) size

len

Python's ____ function returns a string's length when it is passed a string.

B

Python's ____ module supports several ways to generate random numbers. a. rnd c. rand b. random d. randgen

is

Python's ____ operator can be used to test for object identity.

B

Python's ____ operator can be used to test for object identity. a. in b. is c. equals d. refers

B

Python's ____ operator can be used to test for object identity. a. in c. equals b. is d. refers

random

Python's _____ module supports several ways to generate random numbers.

The primary memory of a computer is also sometimes called internal or ________.

Random Access Memory (RAM)

T

Real numbers have infinite precision, which means that the digits in the fractional part can continue forever.

____ is the set of rules that allow an agent to interpret the meaning of those expressions or sentences

SEMANTICS

In Python, a string literal is a sequence of characters enclosed in ____.

SINGLE OR DOUBLE QUOTATION MARKS

Give Python code that removes any occurrences of dashes from a given social security number that variable SSN is assigned to, and updates SSN to contain the dash-removed result

SSN=SSN.replace('-','')

______ is the set of rules for constructing well-formed expressions or sentences in a language

SYNTAX

What are the two different means by which a floating-point number can be written?

Scientific Notation, Decimal Notation

Which forms of control flow require the use of a condition?

Selective, iterative

__________ is the set of rules that allow an agent to interpret the meaning of those expressions or sentences.

Semantics

Which of the three forms of control flow is implicit in a program?

Sequential

Which of the three forms of control is an implicit form of control?

Sequential control

What are the three forms of control flow provided by programming languages?

Sequential, selective, iterative

T

Simple Boolean expressions consist of the Boolean values True or False, variables bound to those values, function calls that return Boolean values, or comparisons.

_______ is the set of algorithms, represented as programs in particular programming languages.

Software

T

Some computer scientists argue that a while True loop with a delayed exit violates the spirit of a while loop.

Define a dictionary named spanish_days that contains as key values the days of the week ('Sunday', 'Monday', etc), in which each key value has the corresponding name in Spanish ('Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado')

Spanish_days={'Sunday':'Domingo','Monady':'Lunes', 'Tuesday':'Miercoles',....}

F (Tim Berners-Lee)

Steve Jobs wrote the first Web server and Web browser software.

When there are no more elements then a ________ exception is raised *

StopIteration

Which of the following exceptions is raised by the next() function to indicate that there is no further item to be returned by iterator RuntimeError StopIteration OverflowError EOFError

StopIteration

What is the term for a program that does not have any control flow, other than sequential control?

Straight-line program

____ can be performed easily from an IDLE window

TESTING

T

THe first electronic digital computers, sometimes called mainframe computers, consisted of vacuum tubes, wires, and plugs, and filled entire rooms.

T

THe interpreter reads a Python expression or statement, also called the source code, and verifies that it is well formed.

A(n) ____ function is a function with the same name as the data type to which it converts

TYPE CONVERSION

B

Tapes and hard disks are an example of____storage media:a)semiconductor, b)magnetic, c)optical, d)primary

________ can be performed easily from an IDLE window.

Testing

T

Testing is a deliberate process that requires some planning and discipline on the programmer's part.

F (least-most)

Text processing is by far the least common application of computing

F (+-*)

The + operator allows you to build a string by repeating another string a given number of times.

F

The == operator returns True if the variables are aliases for the same object. Unfortunately, == returns False if the contents of two different objects are the same.

F (unfortunately, == returns True if the contents are the same)

The == operator returns True if the variables are aliases for the same object. Unfortunately, == returns False if the contents of two different objects are the same.

F

The Boolean days type is named for the twentieth century British mathematician George Boole

D

The CPU, which is also sometimes called a____, consists of electronic switches arranged to perform simple logical, arithmetic, and control operations: a)motherboard, b)chip, c)computing agent, d)processor

A

The L.____() method of the list type removes and returns the element at the end of the list. a. pop b. remove c. get d. append

extend

The L.____(aList) method of the list type adds the elements of L to the end of aList

C

The L.____(aList) method of the list type adds the elements of L to the end of aList. a. join b. concatenate c. extend d. append

C

The L.____(aList) method of the list type adds the elements of L to the end of aList. a. join c. extend b. concatenate d. append

A

The L.____(index) method of the list type removes and returns the element at index. a. pop b. remove c. get d. append

pop

The L.______ () method of the list type removes and returns the element at the end of the list.

D

The Python interpreter rejects any statement that does not adhere to the grammar rules, or____, of the language:a)code, b)library, c)definition, d)syntax

C

The ____ argument of Python's range function specifies a step value. a. first c. third b. second d. fourth

B

The ____ comparison operator is used for equality. a. = c. =: b. == d. :=

D

The ____ data type consists of only two data values—true and false. a. digital c. logical b. binary d. Boolean

getcwd

The ____ file system function returns the path of the current working directory.

chr

The ____ function is the inverse of the ord function.

C

The ____ is the value which is less than half the numbers in the set and greater than the other half. a. variance b. mean c. median d. mode

C

The ____ is the value which is less than half the numbers in the set and greater than the other half. a. variance c. median b. mean d. mode

read

The ____ method of a file object inputs the contents of a file and returns them as a single string.

append

The ____ method of the list type adds an element to the end of the list.

D

The ____ method of the list type adds an element to the end of the list. a. addToEnd b. addLast c. atEnd d. append

D

The ____ method of the list type adds an element to the end of the list. a. addToEnd c. atEnd b. addLast d. append

B

The ____ operator returns False if and only if both of its operands are false, and returns True otherwise. a. and c. not b. or d. xor

append

The ________ method of the list type adds an element to the end of list.

C

The action described by the instruction in an algorithm can be performed effectively or be executed by a____: a)computer, b)processor, c)computing agent, d)program

T

The algorithms that describe information processing can also be represented as information.

T

The assignment symbol can be combined with the arithmetic and concatenation operators to provide augmented assignment operations.

F

The augmented assignment operations have higher precedence that the standard assignment operation.

T

The comparison operators are applied after addition but before assignment

C

The condition in the if-else statement ____ be a Boolean expression. a. may c. must b. should d. must not

1000

The decimal number 8 is expressed as ____ in binary.

T

The definition of the main function and the other function definitions can appear in no particular order in the script, as long as main is called at the very end of the script.

F (integrated circuit)

The development of the transistor in the early 1960s allowed computer engineers to build ever smaller, faster, and less expensive computer hardware components.

B

The escape sequence __ is the newline character a) \l b) \n c) \eof d) \eol

/n

The escape sequence ____ is the newline character.

C

The first line of code in a loop is sometimes called the loop ____. a. iteration b. initialization c. header d. banner

What must be done in order to concatenate a string and a float object?

The float object must be converted to a string object via the str() function.

for i in range(4,22,2):

The following code prints a list of numbers. How would you rewrite the first line if you wanted to print only the even numbers from 4 through 20, including the endpoints? (In your answer, enter your revised version of the first line in its entirety, without including any spaces inside the parentheses.) for i in range(1,51,1): print i

D

The function ____ returns a random number from among the numbers between the two arguments and including those numbers. a. randgen c. random b. randrange d. randint

C

The if statement is also called a ____ selection statement. a. multi-way c. one-way b. Boolean d. two-way

two-way

The if-else statement is also called a ____ selection statement

D

The if-else statement is also called a ____ selection statement. a. multi-way c. one-way b. Boolean d. two-way

two-way

The if-else statement is also called a ______ selection statement.

T

The if-else statement is the most common type of selection statement.

false

The index of the first item in a list is 1

F

The index of the first item in a list is 1.

F (it is 0)

The index of the first item in a list is 1.

F

The index of the last item in a list is the length of the list.

F (it is the length of the list -1)

The index of the last item in a list is the length of the list.

F

The is operator has no way of distinguishing between object identity and structural equivalence.

F (the is operator does distinguish)

The is operator has no way of distinguishing between object identity and structural equivalence.

F

The list method ascending mutates a list by arranging its elements in ascending order.

F (the method sort)

The list method ascending mutates a list by arranging its elements in ascending order.

D

The logical operators have a higher precedence than the ____ operator(s). a. exponentiation c. comparison b. arithmetic negation d. assignment

T

The main function usually expects no arguments and returns no value.

In the waterfall development model, what is the most expensive part of software development?

The maintenance phase

F

The median of a list of values is the value that occurs most frequently.

F (modulus-exponentation)

The modulus operator has the highest precedence and is evaluated first.

T

The most important example of system software is a computer's operating system.

\n

The newline escape character is _______.

T

The not operator expects a single operand and returns its logical negation, True if it's false, and False if it's true.

A

The not operator has a lower precedence than the ____ operator(s). a. comparison c. or b. and d. assignment

F

The not operator has a lower precedence that the and and or operators.

F

The or operator returns True if and only if both of its operands are true, and returns False otherwise.

T

The part of a computer that is responsible for processing data is the CPU.

B

The primary memory of a computer is also sometimes internal or____:a)ROM, b)RAM, c)flash memory, d)associative memory

What effect does the following print statement have? print('Hello' * 5)

The print statement will produce "HelloHelloHelloHelloHello"

F (pushing-returning)

The process of sending a result back to another part of a program is known as pushing a value.

Syntax

The python interpreter rejects any statements that does not adhere to the grammar rules, or ______, of the language.

What statement accurately reflects the difference between the quotient operator and the division operator?

The quotient operator produces an integer, while the division operator produces a float.

an error

The result of evaluating 45%0 is ____.

D

The sequence of steps that describes a computational process is called a(n)____: a)program, b)computing agent, c)pseudocode, d)algorithm

algorithm

The sequence of steps that describes a computational processes is called a(n) ____.

F

The simplest form of selection is the if-else statement.

F

The statements in the loop body need not be indented and aligned in the same column

F

The statements within a while loop can execute one or more times.

false

The string is a mutable data structure.

split

The string method ____ can be used to obtain a list of the words contained in an input string.

join

The string method ____ returns a string that is the concatenation of the strings in the sequence.

split

The string method ______ can be used to obtain a list of words contained in an input string.

Strip

The string method ______ returns a copy of the string with leading and trailing whitespace (tabs, spaces, newlines) removed.

You are reviewing the code written by another programmer, and encounter a variable whose name is entirely in capital letters. What might you discern from this variable name?

The variable is a symbolic constant

F

The while loop is also called a sentinel-control loop, because its condition is tested at the top of the loop.

T

There are two typer of loops-those that repeat an action a predefined number of times and those that perform the action until the program determines that it needs to stop.

C

To delete an entry from a dictionary, one removes its key using the method ____. a. get c. pop b. delete d. remove

:

To extract a substring the programmer places a _____ in the subscript.

C

To halt a loop that appears to be hung during testing, type ____ in the terminal window or in the IDLE shell. a. Control+x c. Control+c b. Control+q d. Control+h

T

To prevent aliasing, a new object can be created and the contents of the original can be copied to it.

When attempting to produce a correct program, what is the point of developing a test suite?

To provide a small set of inputs as a test to verify that a program will be correct for all inputs.

B

To quit the Python shell, you can either select the window's close box or press the____key combination:a)ctrlC, b)ctrlD, c)ctrlZ, d)ctrlX

(T/F) A programmer typically starts by writing high-level language statements in a text editor.

True

(T/F) A variable associates a name with a value, making it easy to remember and use the value later in a program.

True

(T/F) An algorithm describes a process that ends with a solution to a problem.

True

(T/F) An algorithm describes a process that may or may not halt after arriving at a solution to a problem.

True

(T/F) An algorithm solves a general class of problems.

True

(T/F) An important part of any operating system is its file system, which allows human users to organize their data and programs in permanent storage.

True

(T/F) By the mid 1980s, the ARPANET had grown into what we now call the Internet, connecting computers owned by large institutions, small organizations, and individuals all over the world.

True

(T/F) Computer science focuses on a broad set of interrelated ideas.

True

(T/F) Computer scientists refer to the process of planning and organizing a program as software development.

True

(T/F) Each individual instruction in an algorithm is well defined.

True

(T/F) Guido van Rossum invented the Python programming language in the early 1990's.

True

(T/F) If a Python expression is well formed, the interpreter translates it to an equivalent form in a low-level language called byte code.

True

(T/F) In 1984, Apple Computer brought forth the Macintosh, the first successful mass-produced personal computer with a graphical user interface.

True

(T/F) In Python, functions and other resources are coded in components called modules.

True

(T/F) In general, a variable name must begin with either a letter or an underscore (_).

True

(T/F) In the 1960s, batch processing sometimes caused a programmer to wait days for results, including error messages.

True

(T/F) In the early 1940s, computer scientists realized that a symbolic notation could be used instead of machine code, and the first assembly languages appeared.

True

(T/F) Magnetic storage media, such as tapes and hard disks, allow bit patterns to be stored as patterns on a magnetic field.

True

(T/F) Programs rarely work as hoped the first time they are run.

True

(T/F) Steve Jobs wrote the first Web server and Web browser software.

True

(T/F) Testing is a deliberate process that requires some planning and discipline on the programmer's part.

True

(T/F) The algorithms that describe information processing can also be represented as information.

True

(T/F) The first electronic digital computers, sometimes called mainframe computers, consisted of vacuum tubes, wires, and plugs, and filled entire rooms.

True

(T/F) The interpreter reads a python expression or statement also called the source code, and verifies that it is well formed.

True

(T/F) The most important example of system software is a computer's operating system.

True

(T/F) The part of a computer that is responsible for processing data is the central processing unit (CPU).

True

(T/F) When executing the print statement, Python first displays the value and then evaluates the expression.

True

(T/F) When using a computer, human users primarily interact with the memory.

True

A class variable is visible to all instances of a class and does not vary from instance to instance.

True

A condition expresses a hypothesis about the state of its world at that point in time

True

A for loop can be used to iterate through a list, tuple, string, or a dictionary. *

True

A method automatically returns the value None when it includes no return statement.

True

A semantic error is detected when the action that an expression describes cannot be carried out, even though that expression is syntactically correct.

True

A semantic error is detected when the action which an expression describes cannot be carried out even though that expression is syntactically correct

True

A variable associates a name with a value making it easy to remember and use the value later in the program

True

A variable associates a name with a value, making it easy to remember and use the value later in a program.

True

A while loop can be used for a count-controlled loop.

True

All data output to or input from a text file must be strings.

True

Although Python is considered an object-oriented language, its syntax does not enforce data encapsulation.

True

Although the while loop can be complicated to write correctly, it is possible to simplify its structure and thus improve its readability.

True

Ancient mathematicians developed the first algorithms

True

Computer Scientists refer to the process of planning and organizing a program as software and development

True

Computer scientists refer to the process of planning and organizing a program as software development.

True

Conditional iteration requires that a condition be tested within the loop to determine whether the loop should continue

True

Expressions provide an easy way to perform operations on data values to produce other data values

True

Expressions provide an easy way to perform operations on data values to produce other data values.

True

In Python, functions and other resources are coded in components called modules

True

In general, a variable name must begin with either a letter or an underscore (_).

True

In general, a variable name must either begin with a letter or an underscore (_)

True

In the 1930s, the mathematician Blaise Pascal explored the theoretical foundations and limits of algorithms and computation.

True

In the earlier version of Python (Python 2.0) only list comprehensions were allowed. *

True

Inheritance allows a class to automatically reuse and extend the code of similar but more general classes.

True

It is not usual to bother subclassing unless the two classes share a substantial amount of abstract behavior.

True

Modern software development is usually incremental and iterative.

True

Programs rarely work as hoped the first time they are run.

True

Programs rarely work as they are hoped to the first they are run

True

Python programmers typically capitalize their own class names to distinguish them from variable names.

True

Real numbers have infinite precision, which means that the digits in the fractional part can continue forever.

True

Real numbers, have infinite precision, which means that the digits in the fractional part can continue forever

True

Recursive solutions are often more natural and elegant than their iterative counterparts.

True

Simple Boolean expressions consist of the Boolean values True or False, variables bound to those values, function calls that return Boolean values, or comparisons.

True

Some computer scientists argue that a while True loop with a delayed exit violates the spirit of the while loop.

True

The assignment symbol can be combined with the arithmetic and concatenation operators to provide augmented assignment operations.

True

The comparison operators are applied after addition but before assignment

True

The file method write expects a single string as an argument.

True

The following code can be used to set an iterator on a list: <myIter> = iter(<myList>) *

True

The if-else statement is the most common type of selection statement.

True

The not operator expects a single operand and returns its logical negotiation, True , if it's false and False if it's true

True

There are two types of loops, those that repeat an action a predefined number of times (definite iteration) and those that perform the action until the program determines that it needs to stop (indefinite iteration).

True

There is more to software development than writing code

True

To overload an arithmetic operator, you just define a new method using the appropriate method name.

True

True or False? A function is a named group of instructions performing some task.

True

True or False? A function may be called one or more times within a program.

True

True or False? All functions, when they terminate, return to the point in the program from which they were called.

True

True or False? All value-returning functions must have a return statement

True

True or False? Any function in Python that does not contain a return statement returns special value None

True

True or False? Calls to value-returning functions in Python are expressions

True

True or False? Functions can be designed are useful in more than one program.

True

True or False? In Python, program routines are known as functions.

True

True or False? Non-value-returning functions are called for their side effect

True

True or False? The function header of a function definition indicates how the function is to be called

True

Variables receive their initial values and can be reset to new values with an assignment statement.

True

Variables receive their initial values and can be reset to new values with an assignment statement

True

When the Python interpreter evaluates a literal, the value is simply that literal

True

When the Python interpreter evaluates a literal, the value it returns is simply that literal.

True

When the step argument is a negative number, the range function generates a sequence of numbers from the first argument plus 1.

True

When using the open function to open a file for input (i.e., using 'r' as the mode string), if the file does not exist, Python raises an error.

True

You can use parentheses to change the order of evaluation in an arithmetic expression

True

Give section of code that prompts the user for an integer value, and displays the number entered if no exception is raised, otherwise catches the exception when a non-numeric character is entered, displaying the message "non-digit found in input."

Try: Num=int(input("Enter an integer:")) Print(num) Except ValueError: Print("non-digit found in input")

The expression 'Hello' + 10 would raise a _________________ exception on Python

TypeError

______ is a character set.

UNICODE

The default character encoding scheme of Python is ________

UTF-8

Data structure

Unlike an integer, which cannot be factored into more primitive parts, a string is a ______.

break

Using the ____ statement within the body of a loop will cause an exit from the loop.

B

Using the ____ statement within the body of a loop will cause an exit from the loop. a. exit c. stop b. break d. continue

After you initialize a variable, subsequent uses of the variable name in expressions are known as ____.

VARIABLE REFERENCES

The expression int('10A') would raise a ________________ exception on Python

ValueError

T

Variables receive their initial values and can be reset to new values with an assignment statement.

There are several approaches to software development. One version is known as the ____ model.

WATERFALL

Pr

What is "Programming is fun" [:2]?

nothing

What is the output of the following code? x = "Killer Whale" if x == "Nemo": print("You can't do that!") elif x == "Dorie": print("What did you say?") elif x == "Karl": print("Swim Nemo, swim!")

30

What is the output of the following code? x = {} x["Sam"] = 10 x["Sue"] = 20 x["Tom"] = 30 x["Zoe"] = 40 y = (x["Sue"] + x["Zoe"]) / 2 print(y)

A

What will the following loop print on the screen? for count in range(4): print *(*count,*)* a. 0 1 2 3 c. 3 b. 1 2 3 4 d. 4

0 1 2 3

What will the following loop print on the screen? for count in range(4): print count,

F (other way around)

When executing the print statement, Python first displays the value and then evaluates the expression.

T

When replacing an element in a list, the subscript is used to reference the target of the assignment statement, which is not the list but an element's position within it.

T

When the python interpreter evaluates a literal, the value it returns is simply that literal.

T

When the step argument is a negative number, the range function generates a sequence of numbers from the first argument down to the second argument +1.

F

When used with a single list argument, the function maximum returns the largest value contained therein.

F (input and output)

When using a computer, human users primarily interact with the memory.

F (.py)

When writing Python programs, you should use a .pyt extension.

write

Will add characters to the end of a file that has been opened for writing.

readline

Will read a single line from the file, up to and including the first instance of the newline character.

readlines

Will read the entire contents of a file into a list where each line of the file is a string and is an element in the list.

T

You add a new key/value pair to a dictionary by using the subscript operator [].

A

You can join two or more strings to form a new string using the concatenation operator: a) + b) -> c) <-> d) *

T

You can use parentheses to change the order of evaluation in an arithmetic expression

clear( )

You can use the dictionary method ____ to remove all the keys in the dictionary.

A

You can use the dictionary method ____ to remove all the keys in the dictionary. a. clear() c. remove() b. reset() d. zero()

F

You cannot use the equality operator to compare two integer lists.

( )

You indicate a tuple literal in Python by enclosing its elements in

A

You indicate a tuple literal in Python by enclosing its elements in ____. a. () b. [] c. <> d. {}

A

You indicate a tuple literal in Python by enclosing its elements in ____. a. () c. <> b. [] d. {}

Indicate what is displayed by the following. tax = .08 print('Your cost: $', format((1 + tax) * 12.99, '.2f''))

Your cost: $ 14.03

____ is not a valid list in Python.

[2:4] colon is invalid syntax

The escape sequence ____ is the newline character.

\n

The newline escape character is ____.

\n

D

__ can be performed easily from an IDLE window: a) Designing an algorithm b) Writing code c) Compiling d) Testing

A

__ is a protocol for a secure Web page transfer: a) https b) shttp c) xml d) ftps

In order to indicate that an identifier of a given module is to be considered private, the identifier begins and ends with _____________________

___

[2:4]

____ Is not a valid list in python.

George Boole

____ developed a system of logic which consisted of a pair of values, TRUE and FALSE, and a set of three primitive operations on these values, AND, OR, and NOT

{ }

____ is an example of an empty dictionary.

B

____ is an example of an empty dictionary. a. [] c. () b. {} d. <>

C

____ is not a valid list in Python. a. [] b. ['apples','oranges'] c. [2:4] d. [[5, 9], [541, 78]]

C

____ is not a valid list in Python. a. [] c. [2:4] b. ['apples','oranges'] d. [[5, 9], [541, 78]]

B

____ is the format operator. a. & c. ^ b. % d. $

High-level

____ programming languages resemble English and allow the author to express algorithms in a form that other people can understand.

A

____ returns the number of elements in the list. a. len(L) b. siz(L) c. length(L) d. size(L)

B

____consists of the physical devices required to execute algorithms: a)firmware, b)hardware, c)I/O, d)processors

C

____developed a machine that automated data processing for the U.S. Census:a)George Boole, b)Joseph Jacquard, c)Herman Hollerith, d)Charles Babbage

A

____developed a system of logic which consisted of a pair of values, TRUE and FALSE, and a set of three primitive operations on these values, AND, OR, and NOT:a)George Boole, b)Joseph Jacquard, c)Herman Hollerith, d)Charles Babbage

C

____is the set of algorithms, represented as programs in particular programming languages: a)freeware, b)shareware, c)software, d)dataset

D

____programming languages resemble English and allow the author to express algorithms in a form that other people can understand:a)assembly, b)interpreted, c)low-level, d)high-level

D

____took the concept of a programmable computer a step further by designing a model of a machine that bore a striking resemblance to a modrn general-purpose computer:a)George Boole, b)Joseph Jacquard, c)Herman Hollerith, d)Charles Babbage

D

____was considered ideal for numerical and scientific applications:a)COBOL, b)machine code, c)LISP, d)FORTRAN

The main module in Python is given the special name _____________

___main___

Functions that are always available in Python come from what module?

__builtin__

Most classes include a special method named ____, which is the class's constructor.

__init__

tuple

a ______ is a type of sequence that resembles a list, except that unlike a list, it is immutable

parameter

a ______ is the name used in the function definition for an argument that is passed to the function when it is called.

true

a binary number is sometimes referred to as a 'string of bits' or a 'bit string'

false

a caesar cipher uses a plaintext character to compute two or more encrypted characters, and vice versa

syntax error

a character or string incorrectly placed in a command or instruction that causes a failure in execution.

true

a data structure is a compound unit that consists of several smaller pieces of data

method

a function that is defined inside a class and is invoked on instances of that class

local variable

a variable defined inside a function is referred to as ________.

B

a very simple code that has been used for thousands of years is called a(n) cipher: a) RSA b) caesar c) HTTPS d) block

D

a(n) __ cipher uses an invertible matrix to determine the values of the encrypted characters: a) RSA b) caesar c) HTTPS d) block

Give the following values in the exponential notation of Python, such that there is only one significant digit to the left of the decimal point. (a) 4580.5034 (b) 0.00000046004 (c) 5000402.000000000006

a) format(4589.5034, '.1e')= 4.6e+03 b) format(0.00000046004, '.1e')= 4.6e-07 c) format(5000402.000000000006, '.1e')= 5.0e+06

Give an appropriate Boolean expression for each of the following. (a)Determine if variable num is greater than or equal to 0, and less than 100. (b) Determine if variable num is less than 100 and greater than or equal to 0, or it is equal to 200. (c) Determine if either the name 'Thompson' or 'Wu' appears in a list of names assigned to variable last_names. (d) Determine if the name 'Thomson' appears and the name 'Wu' does not appear in a list of last names assigned to variable last_names.

a)(num>=0)and(num<100) b)((num<100) and (num>=0)) or (num==200) c)('Thomspson' in last_names) or ('Wu' in last_names) d)('Thompson' in last_names) and ('Wu' not in last_names)

Regarding variable assignment, (a) What is the value of variables num1 and num2 after the following instructions are executed? num = 0 k = 5 num1 = num + k * 2 num2 = num + k * 2 (b) Are the values id(num1) and id(num2) equal after the last statement is executed?

a)10? b)yes

Give an appropriate expression for each of the following. (a)To determine if the number 24 does not appear in a given list of numbers assigned to variable nums (b) To determine if the name 'Ellen' appears in a list of names assigned to variable names. (c) To determine if a single last name stored in variable last_name is either 'Morris' or 'Morrison'.

a)24 not in nums b)'Ellen' in names c)('Morris' in last_name) or ('Morrison' in last_name)

Give an appropriate if statement for each of the following. (a)An if statement that displays 'within range'if num is between 0 and 100, inclusive. (b) An if statement that displays 'within range'if num is between 0 and 100, inclusive, and displays 'out of range'otherwise.

a)If (num>=0) and (num<=100): print('within range') b)If (num>=0) and (num<=100): print('within range') else: print('out of range')

For each of the following, indicate which is a definite loop, and which is an indefinite loop. (a) num = input('Enter a non-zero value: ') while num == 0: num = input('Enter a non-zero value: ') (b) num = 0 while n < 10: print 2 ** n n = n + 1

a)Indefinite b)Definite

Match the following control flow types to their description (a) sequential control __ based on a condition that is checked once (b) selection control __ implicit form of control (c) iterative control __ based on a condition that may be checked many times

a)b b)a c)c

Match the following Boolean expressions to the expressions that they are logically equivalent to (a) x < y ____ not (x != y) (b) x <= y ____ (not x) or (not y) (c) x == y ____ (not x) and (not y) (d) x != y ____ not (x >= y) (e) not (x and y) ____ not (x == y) (f) not (x or y) ____ not (x > y)

a)c b)e c)f d)a e)d f)b

Regarding the built-in format function in Python, (a) Use the format function to display the floating-point value in variable result with three decimal digits of precision. (b) Give a modified version of the format function in (a) so that commas are included in the displayed results.

a)format(result, '.3f') b)format(result, ',.3f')

Regarding input function in Python, (a) Give an instruction that prompts a user for their last name and stores it in a variable named last_name. (b) Give an instruction that prompts a user for their age and stores it as an integer in a variable named age. (c) Give an instruction that prompts a user for their temperature and stores it as a float in a variable named current_temperature.

a)last_name=input('What is your last name?') b)age=int(input("What is your age?")) c)current_temperature=float(input("What is your temperature?"))

Give a logically equivalent expression for each of the following. (a) num != 25 or num == 0 (b) 1 <= num and num <= 50 (c) not num > 100 and not num < 0 (d) (num < 0 or num > 100)

a)number does not equal 25 or number equals 0 b)1 is less than or equal to num and num is less than or equal to 50 c)number is not greater than 100 and number is not less than 0 d)number is less than 0 or number is greater than 100

In science or any other area of inquiry, a(n) ____________ allows human beings to reduce complex ideas or entities to simpler ones.

abstraction

What term describes the process of substituting a simple process for a complex process in a program to make the program easier to understand and maintain?

abstraction

The sequence of steps that describes a computational process is called a(n) _________

algorithm

The result of evaluating 45%0 is _______.

an error

instance

an object whose type is some class. Instance and object are used interchangeably

In the _________ phase of the waterfall model, the programmers determine what the program will do

analysis

The ____ method of the list type adds an element to the end of the list.

append

A(n) ____ expression consists of operands and operators combined in a manner that is already familiar to you from learning algebra.

arithmetic

A calculated result too small to be represented is referred to as ____________

arithmetic underflow

The values stored in a dictionary are assigned/retrieved by use of a corresponding key value. Therefore, dictionaries in Python are an ___________________ data structure

associative

An object contains a set of __________________ and a set of ____________

attributes, functions

The following code is an example of if grade >= 90: print('Grade of A') else: if grade >= 80: print('Grade of B') else: if grade >= 70: print('Grade of C') else: if grade >= 60: print('Grade of D') else: print('Grade of F') (a) Cascading if Statements (b) Nested if Statements (c) Relational if Statements (d) Invalid Syntax

b)nested if statements

Using function largest in the previous problems, write Python code that gives an example of its use.

bigNum = largest(3,2,6)

A ___________________ is a file containing various types of data, such as numerical data, and is not structured as lines of text

binary file

When writing to or reading from to a file, data is placed in an area of memory called a __________, which make the reading and writing of files more efficient

buffer

The modules of the Python Standard Library are referred to as the Standard ____________ modules

built-in

Which of the floating-point values in question 2 would exceed the representation of the precision of floating points typically supported in Python, as mentioned in the chapter?

c

Match the values with their respective data types (a) 12 __ String (b) 12.45 __ Integer (c) 'Hello' __ Float

c String a Integer b Float

What is displayed by the following? print(format( '-', '->8 '), 'Hello ') a) Hello --- b) --- Hello c) -------- Hello

c) -------- Hello

One can define a(n) ____, in which _init_, _iter_, and _next_ can be defined as per the requirement. *

class

The ____ definition syntax has two parts: a header and a set of method definitions that follow the header.

class

You can use the dictionary method ____ to remove all the keys in the dictionary.

clear()

Any program code that makes use of a given module is called a ____________ of the module

client

Define a set named colors that contains the following colors: 'red', 'blue', 'green', 'yellow'

colors={'red', 'blue', 'green', 'yellow'}

In Python, you can write a print statement that includes two or more expressions separated by _____________.

commas

The action described by the instruction in an algorithm can be performed effectively or be executed by a _________.

computing agent

__init__

constructor

set

contains an unordered collection of unique and immutable objects

A(n) _______ program produces the expected output for any legitimate input.

correct

Examine the following lines of code: current = 1 sum = 0 n = 5 while current <= n: sum = sum + current What is the value of sum after the loop completes all of its iterations? (a) 5 (b) 1 (c) 15 (d) The value of sum will never be available, as this is an infinite loop

d) The value of sum will never be available, as this is an infinite loop

In the modern world of computers, information is also commonly referred to as _______.

data

Write the function header only of a function named largest that takes three integer parameters and returns the largest of the three.

def largest(num1,num2,num3):

Another name for a logic error is a _______ error.

design

In the ________ phase of the waterfall model, the programmers determine how the program will do its task.

design

Top-down

design starts with a global view of the entire problem and breaks the problem into a smaller, more manageable subproblems.

A ____ organizes data values by association with other data values rather than by sequential position.

dictionary

A ____ organizes information by association.

dictionary

In Python, a ____ associates a set of keys with data values.

dictionary

What function can you call inside of IDLE to show the resources of the math module, once it has been imported?

dir(math)

Examine the following Python code: def displayFunction(): print('This program will convert between Fahrenheit and Celsius') print('Enter (C) to convert to Celsius from Fahrenheit') print('Enter (F) to convert to Fahrenheit to Celsius') Write a line of Python code that properly calls function displayFunction.

displayFunction()

The _____________ is used to access a member of an object

dot operator

C

each digit in a binary number has a positional value that is a power of a) 0 b) 1 c) 2 d) 10

One way in which functions serve as abstraction mechanisms is by ____.

eliminating redundant, or repetitious, code

When reading a line from a text file, all the characters up to and including the ___________ character are read and returned

end-of-line

constructor

every class a 'factory' called by the same name as the class, for the making new instances. If the class has an initializer method, this method is used to get the attributes of the new object properly set up

In Python, exceptions can be handled using a try and _____ statements catch finally throw except

except

The section of code that is to be executed when a particular exception has been caught is called an _____________________________

exception handler

Run time errors are known as ________ faults exceptions conditions breaks

exceptions

The L.____(aList) method of the list type adds the elements of L to the end

extend

A Python dictionary is written as a sequence of key/value pairs separated by commas. These pairs are sometimes called indexes.

false

A list is a sequence of data values called indexes.

false

A list is immutable.

false

An Identity function usually tests its argument for the presence or absence of some property.

false

In Python, a try clause can have only one except clause

false

In a dictionary, a -> separates a key and its value.

false

In scripts that include the definitions of several cooperating functions, it is often useful to define a special function named init that serves as the entry point for the script.

false

The == operator returns True if the variables are aliases for the same object. Unfortunately, == returns False if the contents of two different objects are the same.

false

The index of the first item in a list is 1.

false

The index of the last item in a list is the length of the list.

false

The is operator has no way of distinguishing between object identity and structural equivalence.

false

The list method ascending mutates a list by arranging its elements in ascending order.

false

The median of a list of values is the value that occurs most frequently.

false

When used with a single list argument, the function maximum returns the largest value contained therein.

false

You cannot use the equality operator to compare two integer lists.

false

string is an example of a data type in Python

false

In Python, a floating-point number must be written using scientific notation.

false - add or decimal notation

In Python, % is the exponentiation operator.

false - it is **

The index of the first item in a list is 1

false - it is 0

True or False? A location in the turtle graphics window is indicated by an x and y coordinate value relative to the center of the screen in inches.

false->pixels

An algorithm consists of a(n) ____ number of instructions.

finite

In Python, int, long, and ____ are called numeric data types.

float

In Python, int, long, and ________ are called numeric data types.

float

The iterator can be used to manipulate lists, strings, tuples, files, and dictionary, in the same way as a ____ loop. *

for

The built-in _________________ function of Python can be used to control the display of both numeric and string values

format

To import all of the identifiers of a given module so that they do not need to be fully qualified in the importin module, the _______________________ form of import is used

from import*

You are working on a Python script that relies heavily on the cos and sin functions of the math module. As these are the only functions you require, what should you do to import only these functions, rather than the whole math module?

from math import cos, sin

The proper syntax for creating a set containing the values 'apple', 'pear', and 'banana' is __________________________________

fruit={'apple', 'pear', 'banana'}

In a computer program, ____ can enforce a division of labor.

functions

___________ are functions that generate the requisite sequences Iterators Generators Classes Comprehensions

generators

If the existence of a key is uncertain, the programmer can test for it using the dictionary method ____.

has_key

The location that a given value is stored in a dictionary in Python is determined by its key value. The process of determing the storge location of a value based on the value itself is called _________

hashing

One way in which functions serve as abstraction mechanisms is by ____.

hiding complicated details

getter and setter

how are private variables accessed

Build in function _______ can be used in Python to determine if two variables reference the same object in memory

id()

Rewrite the following if-else statements using a single if statement and the elif: header. if temperature >= 85 and humidity > 60: print('muggy day today') else: if temperature >= 85: print('warm, but not muggy today') else: if temperature >= 65: print('pleasant today') else: if temperature <= 45: print('cold today') else: print('cool today')

if (temperature>=85) and (humidity>60): print('muggy day today') elif temperature>=85: print('warm, but not muggy today') elif temperature>=65: print('pleasant today') elif temperature<=45: print('cold today') else: print ('cool today')

Give Python code that displays the longer of two names, name1 and name2

if len(name1) > len(name2): Print (name1) Else: Print(name2)

Suppose that list1 is assigned to a list of tuples. Given the proper code so that a complete copy of list1 is assigned to variable list2

import copy List2=copy.deepcopy(list1)

To import a module name into the namespace of another module, the ____________________ form of import is used

import module name

Give Python code using turtle graphics that draws three squares, one inside of the other as shown below.

import turtle turtle.setup(800,600) window=turtle.Screen() the_turtle=turtle.getturtle() the_turtle.forward(100) the_turtle.left(90) the_turtle.forward(100) the_turtle.left(90) the_turtle.forward(100) the_turtle.left(90) the_turtle.forward(100) the_turtle.left(90) the_turtle.hideturtle() the_turtle.penup() the_turtle.setposition(20,20) the_turtle.showturtle() the_turtle.pendown() the_turtle.forward(60) the_turtle.left(90) the_turtle.forward(60) the_turtle.left(90) the_turtle.forward(60) the_turtle.left(90) the_turtle.forward(60) the_turtle.left(90) the_turtle.hideturtle() the_turtle.penup() the_turtle.setposition(40,40) the_turtle.showturtle() the_turtle.pendown() the_turtle.forward(20) the_turtle.left(90) the_turtle.forward(20) the_turtle.left(90) the_turtle.forward(20) the_turtle.left(90) the_turtle.forward(20)

Commas

in python you can write a print statement that includes two or more expressions, separated by ______.

In a computer, the ______ devices include a keyboard, a mouse, and a microphone.

input

In carrying out the instructions of any algorithm, the computing agent starts with some given information (known as ________).

input

A numeric literal may be an __________ or _________________ value

integer floating point

Truncating division performed on integer operands is referred to as ___________

integer division

The term ____________________ refers to the specification provided for use of a given module. In Python, a _________________ is used to provide such specification

interface, docstring

Python is a(n) _______ language.

interpreted

Python's ____ operator can be used to test for object identity.

is

data structure

is a specialized format for organizing and storing data

If an identifier is written such that it _________________________, then it is unique from all other identifiers in a given program

is fully qualified

The ________ string method in Python can be used to determine if a string contains only letters, whereas the __________ method can be used determine is a string contains only digits

isalpha(), isdigit()

The ________ and __________ string methods in Python can be used to determine if a string contains only lowercase or uppercase characters, whereas the __________ and ___________ methods can be used to convert a string to all lowercase or all uppercase characters

islower(), isupper(), lower(), upper()

immutable

it can't be changed

A list is a sequence of data values called ____.

items

You can use the dictionary method ____ to access a list of the dictionary's

items()

The _______ function returns the iterator of the object passed as an argument *

iter

Suppose that variable k is assigned to a list object that contains a method called numZeros that returns the number of 0 values in the list. Give the proper syntax for calling method numZeros on variable k

k.numZeros()

____ returns the number of elements in the list.

len(L)

A ____ allows the programmer to manipulate a sequence of data values of any types.

list

Give Python code to determine if two lists, list1 and list2, reference two completely different list objects or not

list1 is list2

Suppose that list1 is assigned to a list of integers. Given the proper code so that a complete copy of list1 is assigned to variable list2

list2=list(list1)

A __________ is the way a value of a data type looks to a programmer.

literal

A ________ takes a set of machine language instructions as input and loads them into the appropriate memory locations.

loader

In Python, there are as many as three namespaces that can be active at a given time, these are the _______________ namepace, the ______________ namepace, and the ______________ namespace

local, global, built-in

Tapes and hard disks are an example of ________ storage media.

magnetic

false

many applications now use data mangling to protect information transmitted on networks

The ____ is the value which is less than half the numbers in the set and greater than the other half.

median

A comprehension contains the input sequence along with the expression that represents the ______. x

members

Python's open function, which expects a file pathname and a ____ string as arguments, opens a connection to the file on disk and returns a file object.

mode

Top-down design is an approach for developing a _______________ design

modular

A ___________________ consists of the design and/or implementation of specific functionality

module

Comprehensions can be used for all of the following, except: *

modules

The set type in Python is ______________ , which the frozenset type is _________________

mutable, immutable

Mutable objects have some methods devoted entirely to modifying the internal state of the object. Such methods are called ____.

mutators

A _________________ is when two otherwise distinct entities with the same name become part of the same namespace

name clash

A _______________ is a container that provides a named context for a set of identifiers

namespace

The iterator can move to the next element, using the ____ method *

next()

If a function contains no return statement, Python transfers control to the caller after the last statement in the function's body is executed, and the special value ____ is automatically returned.

none

Give Python code that prompts the user to enter positive integer values, and continues to prompt the user until a value of -1 is entered, adding up all the value entered and displaying the result.

num=int(Input("Enter a positive integer value. Enter -1 to quit")) total=0 while num!=-1: total=total+num num=int(input("Enter another positive integer value. Enter -1 to quit") print("Your total is:", total)

In Python, all classes automatically extend the built-in ____ class, which is the most general class possible.

object

attribute

one of the named data items that makes up an instance

To open a file for reading, the built-in _________ method is used, called with an optional second parameter of ____

open, r

To open a file for writing, the built-in _________ method is used, called with a required second parameter of ____

open, w

Fundamental operations of files include _______ a file, _______ a file, __________ a file, and ___________ a file

opening, reading, writing, closing

CDs and DVDs are an example of ______ storage media.

optical

Which of the following functions and expressions will convert the ASCII character &quot;Z&quot; to its numeric equivalent ASCII code?

ord('Z')

In carrying out the instructions of any algorithm, the computing agent transforms some given information according to well-defined rules, and produces new information, known as ____.

output

A(n) ____ is the name used in the function definition for an argument that is passed to the function when it is called.

parameter

A ____ behaves like a variable and is introduced in a function or method header.

parameter name

Arguments are also known as __________.

parameters

The L.____() method of the list type removes and returns the element at the

pop

The L.____(index) method of the list type removes and returns the element at

pop

To delete an entry from a dictionary, one removes its key using the method ____.

pop

A comprehension may also have an optional _______ expression. *

predictate

Give a call to print that is provided one string that displays the following address on three separate lines. John Doe 123 Main Street Anytown, Maryland 21009

print('John Doe\n123 Main Street\nAnytown, Maryland 21009')

What print statement will output a single '\' character?

print('\\')

In a generator, the values are generated as and when we ______ pause compile proceed repeat

proceed

The CPU, which is also sometimes called a _________, consists of electronic switches arranged to perform simple logical, arithmetic, and control operations.

processor

Algorithms are more often written in a somewhat stylized version of English called ________.

pseudocode

The fundamental operations for altering what is on a stack are ________ and _______

push, pop

Interpreted

python is a _______ language.

An exception is a value (object) that is __________ when an exceptional situation occurs

raised ('thrown')

The _____(n) function generates numbers up to n. *

range

0 through upper -1

range (<upper>) returns a list containing the integers in range _______.

B

range(<upper>) returns a list containing the integers in the range ____. a. 0 through upper b. 0 through upper - 1 c. 1 through upper d. 1 through upper - 1

B

range(<upper>) returns a list containing the integers in the range ____. a. 0 through upper c. 1 through upper b. 0 through upper - 1 d. 1 through upper - 1

When reading a line from a text file, the ________________ method is used

readline

Suppose that list1 and list2 each reference the same list object in memory. Give a set of instruction that would cause the original list reference to be automatically garbage collected

reassign a different object to list1 and reassign a different object to list2

A ____ function is a function that calls itself.

recursive

There are two values associated with an object, its ___________________ value and its ______________________ value

reference, dereferenced

self

referes to current instance or argument

len(L)

returns the number of elements in the list

Each method definition must include a first parameter named ____, even if that method seems to expect no arguments when called.

self

Flash memory sticks are an example of _______ storage media.

semiconductor

The instruction to set the position of a turtle object to the center of the screen is ________________

setposition

The __________ method of turtle graphics in Python is used to create a turtle screen of a specific size.

setup

Numeric literals consist of only the digits 0-9, and optional ________ and ____________

sign character possible decimal point

_ _

signifies a private visibility in a class

In Python, a string literal is a sequence of characters enclosed in ____.

single of double quotation marks

In Python, a string literal is a sequence of characters enclosed in __________.

single or double quotation marks

false

some applications extract portions of strings called characters

sequence

something that can be iterated through

Give Python code that for a first name and last name assigned to variable full_name with the first and last name separated by a single space (e.g., Alice Morgan), assigns the first name to variable first_name and the last name to variable last_name

spaceLoc=full_name.find(' ') first_name=fullname[0,spaceLoc] last_name=fullname[spaceLoc+1, len(fullname)]

Give Python code that, for a first name and last name assigned to variable full_name with the first and last name separated by a single space (e.g., Alice Morgan), displays the first name only

spaceLoc=full_name.find(' ') first_name=fullname[0,spaceLoc] print(first_name)

The predefined exceptions in Python are called the ____________ exceptions

standard

Collectively, the operations performed on strings is called _______________________

string processing

Three example of the types of values that be used as key values of dictionaries in Python are _____________, ________________, and _______________

string, tuple, ?

The Python interpreter rejects any statement that does not adhere to the grammar rules, or ____________, of the language.

syntax

In computer science, data structures organized by association are sometimes

tables

A ___________________ is a file containing characters structured as lines of text, as well as nonprinting characters such as \n, the newline character

text file

C

the _ function is the opposite of the 'ord' function: a) dro b) rord c) chr d) in

false

the absolute value of a digit is determined by raising the base of the system to the power specified by the position

B

the decimal number 6 is __ in binary: a) 100 b) 110 c) 111 d) 1000

D

the decimal number 8 is __ in binary: a) 100 b) 110 c) 111 d) 1000

true

the decimal system is also called base ten

true

the digits of base two are 0 and 1

false

the string is a mutable data structure

Give Python code to create a square of size 100 x 100 such that its bottom left corner is positioned at screen location (0, 0). Use relative positioning to do this. (Assume that the turtle screen has been set up, and that there is a turtle named the_turtle to make use of.)

the_turtle.forward(100) the_turtle.left(90) the_turtle.forward(100) the_turtle.left(90) the_turtle.forward(100) the_turtle.left(90) the_turtle.forward(100)

Give Python code to create a square of size 100 x 100 such that its bottom left corner is positioned at screen location (0, 0). Use absolute positioning to do this. (Assume that the turtle screen has been set up, and that there is a turtle named the_turtle to make use of.)

the_turtle.setposition(0,0) the_turtle.setposition(100,0) the_turtle.setposition(100,100) the_turtle.setposition(0,100) the_turtle.setposition(0,0)

B

to extract a substring, the programmer places a __ in the subscript: a) period b) colon c) semi-colon d) comma

A function can be defined in a Python shell, but it is more convenient to define it in an IDLE window, where it can be saved to a file.

true

A lookup table is a type of dictionary.

true

A variable associates a name with a value, making it easy to remember and use the value later in a program.

true

Although a list's elements are always ordered by position, it is possible to impose a natural ordering on them as well.

true

Anytime you foresee using a list whose structure will not change, you can, and should, use a tuple instead.

true

Each item in a list has a unique index that specifies its position.

true

Expressions provide an easy way to perform operations on data values to produce other data values.

true

If pop is used with just one argument and this key is absent from the dictionary, Python raises an error.

true

In Python, users can create their own exceptions

true

Lists of integers can be built using the range function.

true

Sequences like geometric progression, Fibonacci series, etc., can be easily generated using generator.

true

Testing is a deliberate process that requires some planning and discipline on the programmer's part

true

The definition of the main function and the other function definitions can appear in no particular order in the script, as long as main is called at the very end of the script.

true

The main function usually expects no arguments and returns no value.

true

To prevent aliasing, a new object can be created and the contents of the original can be copied to it.

true

True or False? For a turtle screen size of 600 x 800, the coordinates of the top left corner are (-300, 400)

true

True or False? The can be created numerous turtle objects in a given program.

true

True or False? The use of turtle graphics in Python requires that the turtle module be imported

true

True or False? When a turtle is moved to a new position using the setposition method, a line is drawn from its current location to the new location if the turtle is set to be shown (by use of the showturtle method.)

true

Variables receive their initial values and can be reset to new values with an assignment statement.

true

When replacing an element in a list, the subscript is used to reference the target of the assignment statement, which is not the list but an element's position within it.

true

You add a new key/value pair to a dictionary by using the subscript operator [].

true

You can use parentheses to change the order of evaluation in an arithmetic expression.

true

A(n) ____ is a type of sequence that resembles a list, except that, unlike a list, it is immutable.

tuple

The instruction to get the reference to the "default" turtle in turtle graphics is ______

turtle.getturtle()

A(n) __________ function is a function with the same name as the data type to which it converts.

type conversion

D

unlike an integer, which cannot be factored into more primitive parts, a string is a: a) record b) datum c) data field d) data structure

hash function

used in set, this is why it is more efficient to iterate through

break

using the _____ statement within the body of a loop will cause an exit from the loop.

After you initialize a variable, subsequent uses of the variable name in expressions are known as ________.

variable references

After you initialize a variable, subsequent uses of the variable name in expressions are known as ____.

variable refrences

A ____ is the period of time during program execution when the variable has memory storage associated with it.

variable's lifetime

There are several approaches to software development. One version is known as the ________ model.

waterfall

open

what command do you use to open a text file

Super class

what is the parent class referred to

association

what kind of relationships do dictionaries have, keys /values

true

when used with strings, the left operand of Python's 'in' operator is a target substring and the right operand is the string to be searched

C

when using the subscript operator, the integer expression is also called a(n): a) suffix b) step c) index d) iterator

close

when you are done with a file, you should ____ it.

override

when you rename str, int etc for the object

The ___________ method is used to write to a text file

write

F (you can)

you cannot use the equality operator to compare two integer lists.

()

you indicate a tuple literal in python by enclosing the its elements in ______.

____ is an example of an empty dictionary.

{}


Set pelajaran terkait

Visualizing Physical Geography - Chapter 2

View Set

HBIO301 - study guide modified - not finished

View Set

Changes in Period and Phase Shift of Sine and Cosine Functions

View Set

Vocab Level G Unit 3 Definitions, Synonyms and Antonyms

View Set