Working Master Dec 7th, Python final study

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

MM lstrip(char)

"char" argument is a string containing a character; returns a copy of the string will all instances of "char" that appear at the beginning of the string removed

This symbol marks the beginning of a comment in Python. a. & b. * c. ** d. #

#

This operator performs division, but instead of returning the quotient it returns the remainder. a. % b. * c. ** d. /

%

This operator can be used to find the intersection of two sets. a. I b. & c. - d. ^

&

this operator can be used to find the intersection of two sets

&

What will be assigned to s_string after the execution of the following code? special = '1337 Country Ln.' s_string = special[4: ] a. '1357' b. 'Country Ln. ' c. ' Country Ln.' d. Invalid code

' Country Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:]

' Country Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:]

' Country Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:] '57 C' 'Coun' '1357' ' Country Ln.'

' Country Ln.'

Which method or operator can be used to concatenate lists?

'+'

What will be assigned to the string variable even after the execution of the following code? special='0123456789' even=special[0:10:2]

'02468'

What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2]

'02468'

What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2]

'02468'

What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2] '02020202020202020202' '0123456789' '24682468' '02468'

'02468'

special = '0123456789' some_nums = special [0:10:2]

'02468'

What will be assigned to s_string after the execution of the following code? special='1357 Country Ln.' s_string=special[ :4]

'1357'

What will be assigned to s_string after the execution of the following code? special = '1337 Country Ln.' s_string = special[ :4] a. '1357' b. 'Country Ln.' c. ' Country Ln.' d. Invalid code

'1357'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4]

'1357'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4]

'1357'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4] '7' '7 Country Ln.' '1357' 5

'1357'

What will be the value of the variable string after the following code executes? string = 'abcd' string.upper()

'ABCD'

What will be the value of the variable string after the following code executes? string = 'abcd' string.upper()

'ABCD'

What will be the value of the variable string after the following code executes? string = 'abcd' string.upper()

'ABCD'

What will be assigned to s_string after the execution of the following code? special='1357 Country Ln.' s_string=special[4: ]

'Country Ln.'

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!'

'Hello world!'

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!'

'Hello world!'

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!' ' world!' 'Hello world!' 'Hello' Nothing; this code is invalid

'Hello world!'

What is the value of the variable string after the execution of the following code? string = 'Hello' string += ' world' a. 'Hello' b. ' world' c. 'Hello world' d. Invalid code

'Hello world'

What is the value of the variable string after the execution of the following code? string='Hello' string+='world'

'Hello world'

What will be assigned to s_string after the execution of the following code? special='1357 Country Ln.' s_string=special[-3: ]

'Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:]

'Ln.'

special = '1357 Country Ln.' s_string = special[-3:]

'Ln.'

In what mode do you open a file if you want to write data to it, but you do not want to erase the file's existing contents?

'a' mode

What does the following code display? mystr = 'abc' * 3 print(mystr)

'abcabcabc'

What is the value of the variable string after the execution of the following code? string='abcd' string.upper()

'abcd'

What does the following code display? mystr = 'abcdefg' print(mystr[2:5])

'cde'

Which mode specifier will open a file but not let you change the file or write to it?

'r'

Which mode specifier will open a file but will not let you change the file or write to it?

'r'

In what mode do you open a file that you do not want the file to be changed or written to?

'r' mode

When you open a file for the purpose of retrieving a pickled object from it, what file access mode do you use?

'rb'

Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist?

'w'

Which mode specifier will erase the contents of the file if it already exist and create it if it does not exist?

'w'

When you open a file for the purpose of saving a pickled object to it, what file access mode do you use?

'wb'

What does the following code display? mystr = 'yes' mystr += 'no' mystr += 'yes' print(mystr)

'yesnoyes'

What will be assigned to the string variable pattern after the execution of the following code? i=3 pattern='z'*(5*i)

'zzzzzzzzzzzzzzz'

What will be assigned to the string variable pattern after the following code executes? i = 3 pattern = 'z' * (5 * i) 'zzzzzzzzzzzzzzz' 'z * 15' 'zzzzz' Nothing; this code is invalid

'zzzzzzzzzzzzzzz'

myset=set('a,bb,ccc,dddd')

('a','b','c','d',' ' )

This is an operator that raises a number to a power. a. % b.* c. ** d. /

**

What method or operator can be used to concatenate lists?

+

This operator can be used to find the difference of two sets. a. I b. & c. - d. ^

-

this operator can be used to find the difference of two sets

-

What is the first negative index in a list?

-1

What is the first negative index in a string?

-1

This operator performs integer division. a. // b. % c. ** d. /

//

A bit that is turned off represents the following value: a. 1 b. -1 c. 0 d. "no"

0

This is the first index in a list. a. - 1 b. 1 c. 0 d. The size of the list minus one

0

This is the first index in a string. a. - 1 b. 1 c. 0 d. The size of the string minus one

0

What is the index of the first character in a string?

0

What are the valid indexes for the string 'New York'?

0 through 7

What are the valid indexes for the string 'New York'? -1 through -8 0 through 7 -1 through 6 0 through 8

0 through 7

What are the valid indexes for the string 'New York'? a. 0 through 7 b. 0 through 8 c. -1 through -8 d. -1 through 6

0 through 7

what are the valid indexes for the string 'New_York'?

0 through 7

What number does a bit that is turned on represent? What number does a bit that is turned off represent?

1 represents a bit that is turned on. 0 represents a bit that is turned off.

What two questions should you ask to determine a class's responsibilities?

1) What must the class know? 2) What must the class do?

What will be displayed after the following code is executed? def pass_it(x, y): z = x*y result = get_result(z) return(result) def get_result(number): z = number + 2 return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer)

14

Which of the following statements will cause an error? a. x = 17 b. 17 = X C. X = 99999 d. X = '17'

17 = X

What will display after the following code is executed? def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main()

25

d. KeyError

3. What would be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] a. false b. -1 c. 0 d. KeyError

What will be the output after the following code is executed? def pass_it(x, y): z = y**x return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer)

64

Which of the following is NOT a legal identifier? a. outrageouslyAndShockinglyLongRunon b. _42 c. _ d. lovePotionNumber9 e. 7thheaven

7thheaven

If a string has 10 characters, what is the index of the last character?

9

What types of relationships between values can you test with relational operators?

> greater than < less than >= greater than or equal to <= less than or equal to == equal to != not equal to

What is a flag variable?

A Boolean variable that when the flag value is true it means the condition exists, while a false value of the flag means the condition does not exist.

If you call the index method to locate an item in a list and the item is not found, this happens. a. A ValueError exception is raised. b. An Invalidindex exception is raised. c. The method returns - 1. d. Nothing happens. The program continues running at the next statement.

A ValueError exception is raised.

Global

A ________ constant is a name that references a value that cannot be changed while the program runs.

Global

A ________ variable is accessible to all the functions in a program file.

Local

A ________ variable is created inside a function.

What values can you assign to a bool variable?

A bool variable can only store one of two possible values: True or False. Example: x = true; y = false

What is a compound Boolean expression?

A combination of two or more Boolean expressions using logical operators such as "and", ""or", and "not".

How does a command line interface work?

A command line interface typically displays a prompt, and the user types a command, which is then executed.

What is a condition-controlled loop?

A condition-controlled loop causes a statement or set of statements to repeat as long as a condition is true. In Python you use the "while" statement to write a condition-controlled loop. The while loop gets its name from the way it works: while a condition is true, do some task.

What is a count-controlled loop?

A count-controlled loop iterates a specific number of times. In Python you use the "for" statement to write a count-controlled loop. The for statement is designed to work with a sequence of data items. When the statement executes, it iterates once for each item in the sequence.

What would you call a device that works with binary data?

A digital device. Such as a computer or digital camera.

What is a group of statements that exists within a program for the purpose of performing a specific task?

A function

What is a function?

A function is a group of statements that exist within a program for the purpose of performing a specific task.

What is the scope of a global variable?

A global variable can be accessed by any statement in the program file, including the statements in any function.

nested list

A list that contains other lists as its elements is called a(an) _________.

How is access to a local variable restricted?

A local variable belongs to the function in which it is created, and only statements inside that function can access the variable.

What is an infinite loop?

A loop that has no way of ending and repeats until the program is interrupted.

What is an accessor method?

A method that returns a value from a class's attribute but does not change it

What is a mutator method?

A method that stores a value in a data attribute or changes the value of a data attribute in some other way

False

A mutator method has no control over the way that a class's data attributes are modified.

What is an event-driven program?

A program that responds to events that take place, such as the user clicking a button

When an object is pass as an argument_____.....

A reference to the object

What is a sentinel?

A sentinel is a special value that marks the end of a sequence of values.

Why should you take care to choose a distinctive value as a sentinel?

A sentinel value must be distinctive enough that it will not be mistaken as a regular value in the sequence.

Block

A set of statements that belong together as a group and contribute to the function definition is known as a

field

A single piece of data within a record is called a

What is a file's read position? Where is the read position when a file is first opened for reading?

A special value known as a read position that is internally maintained for that file. A file's read position marks the location of the next item that will be read from the file. Initially, the read position is set to the beginning of the file.

What is a global variable?

A variable that is created by an assignment statement that is written outside all the functions in a program file.

What is a local variable?

A variable that is declared within a function and cannot be accessed by statements that are outside of the function. In addition, a local variable cannot be accessed by code that appears inside the function at a point before the variable has been created.

What is a void function?

A void function is a group of statements that exist within a program for the purpose of performing a specific task. When you need the function to perform its task, you call the function. This causes the statements inside the function to execute. When the function is finished, control of the program returns to the statement appearing immediately after the function call.

What is a problem domain?

A written description of the real-world objects, parties, and major events related to the problem

b. random

A(n) _____ access file is also known as a direct access file. a. sequential b. random c. numbered d. text

sequential

A(n) ________ access file retrieves data from the beginning of the file to the end of the file

Hierarchy

A(n) ________ chart is also known as a structured chart.

slice

A(n) ________ is a span/subsection of items that are taken from a sequence.

Parameter

A(n) ________ is a variable that receives an argument that is passed into a function.

Argument

A(n) ________ is any piece of data that is passed into a function when the function is called.

sequence

A(n) __________ is an object that holds multiple items of data.

slice

A(n) ___________ is a span of items that are taken from a sequence

What will be assigned to the string variable pattern after the following code executes? i = 3 pattern = 'z' * (5 * i) A) 'zzzzzzzzzzzzzzz' B) 'zzzzz' C) 'z * 15' D) Nothing; this code is invalid

A) 'zzzzzzzzzzzzzzz'

What are the valid indexes for the string 'New York'? A) 0 through 7 B) -1 through -8 C) 0 through 8 D) -1 through 6

A) 0 through 7

A set of 128 numeric codes that represent the English letters, various punctuation marks, and other characters is __________ a. binary numbering b. ASCII c. Unicode d. ENIAC

ASCII

Getters

Accessor methods are also known as

Getters

Accessor methods are also known as ________

False

All class definitions are stored in the library so that they can be imported into any program.

When you write data to a file opened in 'a' mode, to what part of the file is the data written?

All data written to the file will be appended to its end.

False

All instances of a class share the same values of the data attributes in the class.

False

An "is a" relationship exists between a grasshopper and a bumblebee.

What happens if you try to use an invalid index to access a character in a string?

An IndexError Exception occurs

This will happen if you try to use an index that is out of range for a string. a. A ValueError exception will occur. b. An IndexError exception will occur. c. The string will be erased and the program will continue to run. d. Nothing-the invalid index will be ignored.

An IndexError exception will occur.

Which of the following is not true? a. An algorithm allows ambiguity. b. An algorithm, when carried out, must eventually stop. c. An algorithm, can be carried out by a human being.

An algorithm allows ambiguity.

What is an instance attribute?

An attribute that belongs to a specifjc instance of a class

True

An exception handler is a piece of code that is written using the try/except statement.

Briefly describe how the "and" operator works.

An expression formed by the "and" operator is true only when both the 'first' and 'second' sub expressions are true. If the left sub expression is false then it will not check the right sub expression because the overall expression has already been determined as false, this is called "short cut evaluation".

Briefly describe how the "or" operator works.

An expression formed by the "or" operator is false only when both the 'first' and 'second' sub expressions are false. If the left sub expression is true then it will not check the right sub expression because the overall expression has already been determined as true, this is called "short cut evaluation".

What is an object?

An object is a software entity that contains both data and procedures.

List

An object that contains multiple data items. Lists are mutable, which means that their contents can be changed during a program's execution.

The _______________ method is commonly used to add items to a list.

Append

A(n) ________ is any piece of data that is passed into a function when the function is called.

Argument

d. customer.write('Mary Smith')

Assume that the customer file references a file object, and the file was opened using the 'w' mode specifier. How would you write the string 'Mary Smith' to the file? a. customer_file.write('Mary Smith') b. customer.write('w','Mary Smith') c. customer.input('Mary Smith') d. customer.write('Mary Smith')

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:] A) 'Coun' B) ' Country Ln.' C) '1357' D) '57 C'

B) ' Country Ln.'

What is the first negative index in a string? A) 0 B) -1 C) -0 D) the size of the string minus one

B) -1

Why do global variables make a program difficult to debug?

Because any statement in a program file can change the value of a global variable. If you find that the wrong value is being stored in a global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. In a program with thousands of lines of code, this can be difficult.

Why are library functions like " black boxes" ?

Because you do not see the internal workings of library functions, the term "black box" is used to describe any mechanism that accepts input, performs some operation (that cannot be seen) using the input, and produces output.

Does the while loop test its condition before or after it performs an iteration?

Before; The while loop is known as a pretest loop, which means it tests its condition before performing an iteration.

A(n) _________ file contains data that has not been converted to text.

Binary

A set of statements that belong together as a group and contribute to the function definition is known as a..

Block

A(n) _____ expression has a value of either true or false. a. binary b. decision c. unconditional d. Boolean

Boolean

This type of function returns either True or False. a. Binary b. true false c. Boolean d. logical

Boolean

What type of function can be used to determine whether a number is even or odd?

Boolean

What is a Boolean expression?

Boolean expressions check the truth of an expression, it checks whether the expression is true or false.

how do you call the ____str___method?

Both a and b

How do you call the _ _str_ _ method?

By passing the object to the built-in str method

In a Python class, how do you hide an attribute from code outside the class?

By starting the attribute's name with two underscores

How do you delete an element from a dictionary?

By using the del statement

How do you find the number of elements in a list?

By using the len Function. The len function takes the list as an argument and it returns the number of the elements present in the list .

How do you determine the number of elements that are stored in a dictionary?

By using the len function

When a program runs on a computer, the part of the computer that carries out the instructions is called the _______.

CPU

What are the advantages of breaking a large program into modules?

Called "Modular programming". Large programs are easier to understand, debug and maintain when they are divided into modules. Modules also make it easier to reuse the same code in more than one program.

______ buttons, which may appear alone or in groups, allow the user to make yes/no or on/off selections.

Check

True

Closing a file disconnects the communication between the file and the program

True

Closing a file disconnects the communication between the file and the program.

Why should a program close a file when it's finished using it?

Closing a file disconnects the program from the file. In some systems, failure to close an output file can cause a loss of data.

What is the purpose of closing a file?

Closing a file disconnects the program from the file. The process of closing an output file forces any unsaved data that remains in the buffer to be written to the file. In some systems, failure to close an output file can cause a loss of data.

Encapsulation

Combining data and code in a single object is known as

encapsulation

Combining data and code in a single object is known as

What is the difference between a compiler and an interpreter?

Compiler Compiler is a program that translates a high level code into machine language. In case of this, compiling and executing are two different processes. Compiler scans the entire program on the whole and report for errors. Example: C++ programming language uses compiler. Interpreter Interpreter is a special program that does the translation and simultaneously executes each and every instruction also. In this, both translation and execution are done simultaneously. Interpreter performs the translation and execution line by line and reports the error if any. Example: Python Programming language uses interpreter.

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:] A) 'y Ln' B) '135' C) '753' D) 'Ln. '

D) 'Ln. '

What is the return value of the string method lstrip()? A) the string with all whitespaces removed B) the string with all leading tabs removed C) the string with all leading spaces removed D) the string with all leading whitespaces removed

D) the string with all leading whitespaces removed

what happens when a piece of data is written to a file?

Data is copied from a variable in the RAM to a file

What is a decision structure?

Decision structures are control structures which provide a different set of instructions to be executed based on different choices made by the user.

What is the number of the first index in a dictionary? a. 1 b. 0 c. the size of the dictionary minus one d. Dictionaries are not indexed by number.

Dictionaries are not indexed by number.

What is meant by the phrase "divide and conquer" ?

Dividing a large program or task into several smaller tasks that are easily managed and performed.

How does a dual alternative decision structure work?

Dual alternative decision structure is a control structure with two possible paths of execution. The program will follow one path if condition equals true and another if condition equals false.

You need to test a condition and then execute one set of statements if the condition is true. If the condition is false, you need to execute a different set of statements. What structure will you use?

Dual alternative decision structure.

What will be the output after the following code is executed and the user enters 75 and 0 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') main()

ERROR: cannot have 0 items

index

Each element in a tuple has a(n) ________ that specifies its position in the tuple.

index

Each element in a tuple has a(n) __________ that specifies its position in the tuple

What is a loop iteration?

Each execution of the body of a loop is known as an iteration

What are the data items in a list called?

Elements

What is encapsulation?

Encapsulation is the combining of data and code into a single object.

An area in which the user may type a single line of input from the keyboard.

Entry

When a function is called by its name during the execution of a program, then it is..

Executed

A filename________ is a short sequence of characters that appear at the end of a filename, preceded by a period.

Extension

Arrays, which most other programming languages allow, have much more capabilities than list structures.

FALSE

Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.

FALSE

The sort method rearranges the elements of a list so they appear in ascending or descending order.

FALSE

A single piece of data within a record is called a ?

FIELD

A class method does not have to have a self parameter. T or F

False

A file object's writelines method automatically writes a newline ( '\n' ) after writing each list item to the file. T or F

False

A flowchart shows the hierarchical relationships between functions in a program. T or F

False

A function definition specifies what a function does and causes the function to execute.

False

A hierarchy chart shows all the steps that are taken inside a function.

False

A list can be a dictionary key. T or F

False

A list cannot be passed as an argument to a function.

False

A local variable can be accessed from anywhere in the program.

False

A program can be made of only one type of control structure. You cannot combine structures. T or F

False

A single alternative decision structure tests a condition and then takes one path if the condition is true, or another path if the condition is false. T or F

False

A statement in one function can access a local variable in another function. T or F

False

A syntax error does not prevent a program from being compiled and executed. T or F

False

Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures.

False

Assembly language is considered a high-level language. T or F

False

Assume list1 references a list. After the following statement executes, list1 and list2 will reference two identical but separate lists in memory: list2 = list1 T or F

False

Calling a function and defining a function mean the same thing. T or F

False

Function names should be as short as possible. T or F

False

If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode, then an alert will appear on the screen.

False

If you do not handle an exception, it is ignored by the Python interpreter, and the program continues to execute. T or F

False

If you print a variable that has not been assigned a value, the number 0 will be displayed. T or F

False

Images, like the ones you make with your digital camera, cannot be stored as binary numbers. T or F

False

In Python there is no restriction on the name of a module file.

False

In Python you cannot write functions that accept multiple arguments. T or F

False

In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.

False

Indexing of a string starts at 1 so the index of the first character is 1, the index of the second character is 2, and so forth.

False

Indexing of a string starts at 1 so the index of the first character is 1, the index of the second character is 2, and so forth. T/F

False

Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth

False

It is a common practice in object-oriented programming to make all of a class's data attributes accessible to statements outside the class. T or F

False

It is not necessary to initialize accumulator variables. T or F

False

Lists in Python are immutable. T or F

False

One of the drawbacks of a modularized program is that the only structure you can use in such a program is the sequence structure.

False

One way to find the classes needed for an object-oriented program is to identify all of the verbs in a description of the problem domain. T or F

False

Only the __ init __ method can be overridden. T or F

False

Programmers must be careful not to make syntax errors when writing pseudocode programs. T or F

False

Python allows the programmer to work text and number files.

False

Python allows the programmer to work with text and number files.

False

Sets are created using curly braces { } A. True B. False

False

Sets are immutable.

False

T/F: A mutator method has no control over the way that a class's data attributes are modified.

False

T/F: All class definitions are stored in the library so that they can be imported into any program.

False

T/F: All instances of a class share the same values of the data attributes in the class.

False

T/F: An "is a" relationship exists between a grasshopper and a bumblebee.

False

T/F: An object is a stand-alone program but is used by programs that need its service.

False

T/F: In a UML diagram the first section holds the list of the class's methods.

False

T/F: Sets are created using curly braces { }.

False

T/F: Sets are immutable.

False

T/F: The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs.

False

The dictionary method popitem does not raise an exception if it is called on an empty dictionary. T or F

False

The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs.

False

The else suite in a try/except statement executes only if a statement in the try suite raises an exception. T or F

False

The finally suite in a try/except statement executes only if no exceptions are raised by statements in the try suite. T or F

False

The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

False

The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr) T/F

False

The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

False

The following expression is valid: string[i] = 'i'

False

The following expression is valid: string[i] = 'i'

False

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. False and False

False

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. False and True

False

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. False or False

False

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. True and False

False

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. not True

False

The following statement creates an empty set: myset = ( ) T or F

False

The index of the first element in a list is 1, the index of the second element is 2, and so forth.

False

The isupper method converts a string to all uppercase characters. T or F

False

The keys in a dictionary must be mutable objects.

False

The keys in a dictionary must be mutable objects. T or F

False

The math function atan(x) returns one tangent of x in radians.

False

The phrase " divide and conquer" means that all of the programmers on a team should be divided and work in isolation. T or F

False

The process of input validation works as follows: when the user of a program enters invalid data, the program should ask the user "Are you sure you meant to enter that?" If the user answers "yes," the program should accept the data. T or F

False

The process of opening a file is only necessary with input files. Output files are automatically opened when data is written to them. T or F

False

The remove method removes all occurrences of an item from a list.

False

The sort method rearranges the elements of a list so they are in ascending or descending order.

False

The union of two sets is a set that contains only the elements that appear in both sets.

False

To add a descriptive label to the X and Y axes of a graph when using the matplotlib package, you need to import the labels module.

False

To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops. T or F

False

Today, CPUs are huge devices made of electrical and mechanical components such as vacuum tubes and switches. T or F

False

True/False: A class definition is stored in the library so that it can be imported into any program.

False

True/False: A mutator method has no control over the way that a class's data attributes are modified.

False

True/False: An expression of the form string[i] = 'i' is a valid expression.

False

True/False: An object is a stand-alone program but is used by programs that need its service.

False

True/False: Arrays, which most other programming languages allow, have much more capabilities than list structures.

False

True/False: In a UML diagram, the middle section holds the list of the class's methods.

False

True/False: In python, there is nothing that can be done if the program tries to access a file that does not exist

False

True/False: Indexing of a string starts at 1, so the index of the first character is 1, the index of the second character is 2, and so forth.

False

True/False: Indexing of strings starts at 1, so the index of the first character is 1, the index of the second character is 2

False

True/False: Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.

False

True/False: The instances of a class share the data attributes in the class.

False

True/False: The isupper method converts a string to all upper case characters

False

True/False: The sort method rearranges the elements of a list so they appear in ascending or descending order.

False

True/False: The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.

False

True/False: When a piece of data is read from a file, it is copied from the file into the program

False

True/False: When you call a string's split method, the method divides the string into two substrings

False

True/False: if a file with the specified name already exists when the file is opened, and the file is opened in 'w' mode, then an alert will appear on the screen

False

Unfortunately, there is no way to store and call on functions when using turtle graphics.

False

Unlike other languages, in Python the number of values a function can return is limited to one.

False

Variable names can have spaces in them. T or F

False

When a file that already exists is opened in append mode, the file's existing contents are erased. T or F

False

When a piece of data is read from a file it is copied from the file into the program.

False

When a piece of data is read from a file, it is copied from the file into the program.

False

When accessing each character in a string, such as for copying purposes, you would typically use a while loop.

False

When working with a sequential access file, you can jump directly to any piece of data in the file without reading the data that comes before it. T or F

False

When you call a string's split method, the method divides the string into two substrings. T or F

False

Windows, Linux, Android, iOS, and Mac OSX are all examples of application software. T or F

False

Word processing programs, spreadsheet programs, email programs, web browsers, and games are all examples of utility programs. T or F

False

You can remove an element from a tuple by calling the tuple's remove method. T or F

False

You can store duplicate elements in a set. T or F

False

You can write any program using only sequence structures. T or F

False

You cannot have both keyword arguments and non-keyword arguments in a function call. T or F

False

You cannot use a for loop to iterate over the characters in a string.

False

You do not need to have an import statement in a program to use the functions in the random module. T or F

False

Sets are created using curly braces { }.

False (creates an empty dictionary)

A list can be a dictionary key

False - must be IMMUTABLE

The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

False, will print 'yesno'

A single piece of data within a record is called a

Field

When a program needs to save data for later use, it writes the data in a(n)________

File

What does a professional programmer usually do first to gain an understanding of a problem?

First gain the requirement of the program for which it is being designed. Requirements include the task or goals which the program has to perform.

How do you identify the potential classes in a problem domain description?

First, identify the nouns, pronouns, and pronoun phrases in the problem domain description. Then, refine the list to eliminate duplicates, items that you do not need to be concerned with in the problem, items that represent objects instead of classes, and items that represent simple values that can be stored in variables.

What is a flag and how does it work?

Flags are Boolean variables that indicate whether a specific condition exists or not. When the flag value is true it means the condition exists, while a false value of the flag means the condition does not exist.

What is the difference between floating-point division and integer division?

Floating point division, /, - returns the output in floating data type. It gives the result in decimal places. Integer division, //, - returns the output in integer value. It ignores the decimal place value.

Which of the following functions returns the largest integer that is less than or equal to its argument?

Floor

Name and describe the two parts of a function definition.

Function Header - the first line of the function definition. It marks the beginning of the function definition. The function header begins with the key word def, followed by the name of the function, followed by a set of parentheses, followed by a colon. Block - is a set of statements that belong together as a group. These statements are performed any time the function is executed.

A function definition has what two parts?

Function Header; Block

How can functions make the development of multiple programs faster?

Functions can be written for the commonly needed tasks, and those functions can be incorporated into each program that needs them.

What does the phrase "garbage in, garbage out" mean?

GIGO; refers to the fact that computers cannot tell the difference between good data and bad data. If a user provides bad data as input to a program, the program will process that bad data and, as a result, will produce bad data as output. The integrity of a program's output is only as good as the integrity of its input.

What will be the output after the following code is executed? def pass_it(x, y): z = x + ", " + y return(z) name2 = "Tony" name1 = "Gaddis" fullname = pass_it(name1, name2) print(fullname)

Gaddis, Tony

Describe the steps that are generally taken when an input validation loop is used to validate data.

Get input Validate input Input = good? Go to next Input = bad? Display error, get input again

customer.write('Mary Smith')

Given that the customer file references a file object, and the file was opened using the 'w' mode specifier, how would you write the string 'Mary Smith' to the file?

Vegetable

Given the following line of code, in a UML diagram, what would the open arrowhead point to? class Celery(Vegetable):

A ________ constant is a name that references a value that cannot be changed while the program runs.

Global

A ________ variable is accessible to all the functions in a program file.

Global

Which of these is not a programming language? a. C b. C++ c. HTML d. Java

HTML

The first line in a function definition is known as the function..

Header

A(n) ________ chart is also known as a structured chart.

Hierarchy

b. Two (Text and Binary)

How many types of files are there? a. One b. Two c. Three d. Four

This operator can be used to find the union of two sets. a. I b. & c. - d. ^

I

What type of exception does a program raise when it tries to open a nonexistent file?

IOError

This is a design tool that describes the input, processing, and output of a function. a. hierarchy chart b. IPO chart c. datagram chart d. data processing chart

IPO chart

If a file already exists what happens to it if you try to open it as an output file (using the ' w ' mode )?

If a file with the specified name already exists when the file is opened, the contents of the existing file will be erased.

How do functions help you reuse code in a program?

If a specific operation is performed in several places in a program, a function can be written once to perform that operation and then be executed any time it is needed.

Why is it critical that accumulator variables are properly initialized?

If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.

What is the difference between the remove and discard methods?

If the specified element to delete is not in the set, the remove method raises a KeyError exception, but the discard method does not raise an exception.

greater than

If the start index is ____ the end index, the slicing expression will return an empty string.

c. greater than

If the start index is _____ the end index, the slicing expression will return an empty string. a. equal to b. less than c. greater than d. not equal to

When designing an object-oriented application, who should write a description of the problem domain?

If you adequately understand the nature of the problem you are trying to solve, you can write a description of the problem domain yourself. If you do nor thoroughly understand the nature of the problem, you should have an expert write the description for you.

Tuples are _______________ sequences, which means that once a tuple is created, it cannot be changed

Immutable

Which of the following statements causes the interpreter to load the contents of the random module into memory?

Import random

False

In a UML diagram the first section holds the list of the class's methods.

d. key

In a dictionary, you use a(n) _____ to locate a specific value. a. datum b. element c. item d. key

Key

In a dictionary, you use a(n) ________ to locate a specific value.

Key

In a dictionary, you use a(n)________ to locate a specific value.

Command line

In a(n) ________ interface, a prompt is displayed that allows the user to enter a command which is then executed.

the user interface

In an event-driven environment, the user interacts with

operating system

In an event-driven program, the ________ accepts the user's commands.

If an exception is raised and the program does not handle it with a try/except statement, what happens?

In most cases, an exception causes a program to abruptly halt.

identify the classes needed

In object-oriented programming, one of first tasks of the programmer is to

Identify the classes needed

In object-oriented programming, one of the first task of the programmer is to

c. in

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the _____ operator. a. included b. of c. in d. not in

In

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the ________ operator.

Why must you indent the statements in a block?

Indentation is required because the Python interpreter uses it to tell where the block begins and ends.

Each element in a tuple has a(n) _______________ that specifies its position in the tuple.

Index

What three things are listed on an IPO chart?

Input Processing Output

Give a general description of the input validation process.

Input validation is the process of inspecting data that has been input to a program, to make sure it is valid before it is used in a computation. Input validation is commonly done with a loop that iterates as long as an input variable references bad data.

insert(index, item) Method

Inserts an item into the list at the specified index.

The Python library functions that are built into the Python ________ can be used by simply calling the required function.

Interpreter

What will display after the following code executes? password = 'ILOVEPYTHON' if password.isalpha(): print('Invalid, must contain one number.') elif password.isdigit(): print('Invalid, must have one non-numeric character.') elif password.isupper(): print('Invalid, cannot be all uppercase characters.') else: print('Your password is secure!') Invalid, must have one non-numeric character. Invalid, must contain one number.Invalid, cannot be all uppercase characters. Your password is secure! Invalid, must contain one number.

Invalid, must contain one number.

Explain what is meant by the term "conditionally executed."

Is a set of statements that are executed only when a certain condition is true. If the condition is false they will not be executed. Also called a single alternative decision structure.

What best defines a "programming language"? a. It allows us to control a computer. b. It allows us to make a calculation. c. It allows to execute a program. d. It allows us to express an algorithm.

It allows us to express an algorithm

What is pseudocode?

It is an informal description of the algorithm.

Global

It is recommended that programmers avoid using ________ variables in a program whenever possible.

Why is the CPU the most important component in a computer?

It is the brain of the computer and is the place that actually runs the programs.

What is a parameter variable's scope?

It is the function in which the parameter is used. All of the statements inside the function can access the parameter variable, but no statement outside the function can access it.

What is a variable's scope?

It is the part of a program in which the variable may be accessed.

What is the purpose of the _ _str_ _ method?

It returns a string representation of the object.

What does the items method return?

It returns all a dictionary's keys and their associated values as a sequence of tuples.

What does the keys method return?

It returns all the 'keys' in a dictionary as a sequence of tuples.

What does the values method return?

It returns all the 'values' in the dictionary as a sequence of tuples.

If an existing file is opened in append mode, what happens to the file's existing contents?

It will not be erased and new data will be written at the end of the file's current contents.

What is the purpose of the _ _init_ _ method? When does it execute?

Its purpose is to initialize an object's data attributes. It executes immediately after the object is created.

What does the following snippet of code produce? name = 'Juliet' for ch in name: print(ch)

J u l I e t

What does the following code display? name = 'Joe' print(name.upper()) print(name.lower()) print(name)

JOE joe joe

What would be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] false -1 0 KeyError

Key Error

An element in a dictionary has two parts. What are they called?

Key and value

What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna']

KeyError

What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] -1 False 0 KeyError

KeyError

What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] a. KeyError b. False c. 0 d. -1

KeyError

What will be the result of the following code?ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 }value = ages['Brianna']

KeyError

ages = {'Aaron' " 6, 'Kelly':3,'Abigail':1} value = ages ['Brianna']

KeyError

What are the words that make up a high-level programming language called?

Keywords because they are the words that convey special meaning to the compiler or interpreter.

Write a statement that displays the number of elements in the list cities. Write a second statement that displays the number of characters in the string variable city.

Len(cities) Len('city')

Python comes with ________ functions that have already been prewritten for the programmer.

Library

mutable

Lists are ___________, which means their elements can be changed in a program

True

Lists are dynamic/mutable data structures such that items may be added to them or removed from them.

A ________ variable is created inside a function.

Local

Which statement is NOT true: a. Machine languages can be used to express algorithms. b. Machine languages can be used to write programs that can run on any machine. c. Machine language consists of zeros and ones. d. Machine language is produced by compilers.

Machine languages can be used to write programs that can run on any machine.

The Python standard library's ________ module contains numerous functions that can be used in mathematical calculations.

Math

A menu that is displayed on the screen and may be clicked by the user

Menubutton

Displays multiple lines of text.

Message

What is a repetition structure?

More commonly known as a loop, a repetition structure causes a statement or set of statements to execute repeatedly as many times as necessary.

Lists are _______________, which means their elements can be changed.

Mutable

Setters

Mutator methods are also known as

Does a set allow you to store duplicate elements?

No

Will all of a class's actions always be directly mentioned in the problem domain description?

No, not always

When a parameter is changed, does this affect the argument that was passed into the parameter?

No; the changes made to a parameter do not affect the arguments.

If the input that is read by the priming read is valid, how many times will the input validation loop iterate?

None

What will be the output after the following code is executed? def pass_it(x, y): z = x , ", " , y num1 = 4 num2 = 8 answer = pass_it(num1, num2) print(answer)

None

What is the number of the first index in a dictionary?

None - elements not stored in any particular order

Which of the following names in a program is equivalent to the name int? a. Int b. INT c. All of the above d. None of the above

None of the above

What will be the output after the following code is executed? import matplotlib.pyplot as plt def main(): x_crd = [0, 1 , 2, 3, 4, 5] y_crd = [2, 4, 5, 2] plt.plot(x_crd, y_crd) main()

Nothing; the number of x-coordinates do not match the number of y-coordinates.

What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') main()

Nothing; there is no print statement to display average. The ValueError will not catch the error.

Which of the following will assign a random integer in the range of 1 through 50 to the variable number?

Number = random.randint(1,50)

True

Object-oriented programming allows us to hide the object's data attributes from code that is outside the object.

In this chapter, we use the metaphor of a cookie cutter and cookies that are made from the cookie cuter to describe classes and objects. In this metaphor, are objects the cookie cutter, or the cookies?

Objects are the cookies.

What statements are able to access a local variable?

Only statements inside that function can access the variable in the function.

Describe the three steps that must be taken when a file is used by a program.

Open file - Opening a file creates a connection between the file and the program. Opening an output file usually creates the file on the disk and allows the program to write data to it. Opening an input file allows the program to read data from the file. Process file - In this step data is either written to the file (if it is an output file) or read from the file (if it is an input file ). Close file - When the program is finished using the file, the file must be closed. Closing a file disconnects the file from the program.

What three steps must be taken by a program when it uses a file?

Open the file Process the file Close the file

There is a list called fruits having 5 elements and a file named fruit_file. Given that the file is properly opened, which statement writes one line of output to the file (assume the file is properly closed).

Outfile.write(fruit_file+'\n')

When data is written to a file, it is described as a(n)_______ file.

Output

A(n) ________ is a variable that receives an argument that is passed into a function.

Parameter

What are private methods?

Private methods cannot be accessed by entities outside the object. They are designed to be accessed internally.

True

Procedures operate on data items that are separate from the procedures.

What are the advantages of using a tuple rather than a list?

Processing a tuple is faster rather than a list

What is the advantage of using tuples over lists?

Processing a tuple is faster than processing a list.

Give two reasons why tuples exist.

Processing a tuple is faster than processing a list. Tuples are safe. Because you are not allowed to change the contents of a tuple, you can store data in one and that data can not be modified (accidentally or otherwise) by any code in your program.

What is an advantage of using a tuple rather than a list?

Processing, Tuple faster than a list

What are public methods?

Public methods can be accessed by entities outside the object.

Standard

Python comes with ________ functions that have already been prewritten for the programmer.

if the 'start' index specifies a position before the beginning of the string:

Python will use 0 instead

if the 'end' index specifies a position beyond the end of the string:

Python will use the length of the string instead

When a program runs on a computer, it is stored in _______.

RAM

This is a volatile type of memory that is used only for temporary storage while a program is running. a. RAM b. secondary storage c. the disk drive d. the USB drive

RAM (Random Access Memory)

A_________ access file is also know as a direct access file?

RANDOM

What is the process of retrieving data form a file called

READING DATA

______ buttons normally appear in groups of two or more and allow the user to select one of several possible options.

Radio

If there are a group of these in a container, only one of them can be selected at any given time. a. Checkbutton b. Radiobutton c. Mutualbutton d. Button

Radiobutton

Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it?

Random

A(n)________ access file is also known as a direct access file.

Random Access file

If data is retrieved from a file by a program, this is known by the term______ file.

Read

Computer programs typically perform what three steps?

Receiving of input Processing of input Producing output from received input

remove(item) Method

Removes the first occurrence of the item from the list. A ValueError exception is raised if the item is not found in the list.

In a value-returning function, the value of the expression that follows the keyword ________ will be sent back to the part of the program that called the function.

Return

index( item) Method

Returns the index of the first element whose value is equal to item. A ValueError exception is raised if item is not found in the list.

The _______________ method reverses the order of the items in the list.

Reverse

reverse() Method

Reverses the order of the items in the list.

The ________ of a local variable is the function in which that variable is created.

Scope

A(n) _______________ is an object that holds multiple items of data.

Sequence

Object that contains multiple items of data

Sequence

A(n)______ access file retrieves data from the beginning of the file to the end of the file.

Sequential

______ a object is the process of converting the object to a stream of bytes that can be saved to a file for later retrieval.

Serializing

False

Sets are created using curly braces { }.

False

Sets are immutable.

What is a single alternative decision structure?

Single alternative decision structure is a control structure that only provides one alternative path of execution. If the condition is true the alternative path is taken, if the condition is false the alternative path is skipped.

A(n) _______________ is a span of items that are taken from a sequence.

Slice

sort() Method

Sorts the items in the list so they appear in ascending order (from the lowest value to the highest value).

You created the following dictionary relationships = {'Jimmy':'brother'}. You then executed the following code, and received a KeyError exception. What is the reason for the exception? relationships['jimmy'] String comparisons are case sensitive so 'jimmy' does not equal 'Jimmy'. You used the wrong syntax for creating the dictionary. You should have used the code relationships['brother']. There is a bug in Python.

String comparisons are case sensitive so 'jimmy' does not equal 'Jimmy'.

What is the return value of the string method lstrip()?

String with all white spaces removed

True

Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.

What type of software controls the internal operations of the computer's hardware?

System Software. Such as Windows, Linux, Mac OS

In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.

TRUE

Invalid indexes do not cause slicing expressions to raise an exception.

TRUE

Lists are dynamic data structures such that items may be added to them or removed from them.

TRUE

The first step in calculating the average of the values in a list is to get the total of the values.

TRUE

A(n) ________ file contains data that has been encoded as text using as scheme such as ASCII.

Text

Fibonacci series

The Fibonacci numbers, named after the Italian mathematician Leonardo Fibonacci, are a sequence of numbers that after the second number, each number in the series is the sum of the two previous numbers.

Interpreter

The Python library functions that are built into the Python ________ can be used by simply calling the required function.

True

The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y and y = 0.

try

The ________ block in try-except structure includes one or more statements that can potentially raise an exception.

Top-Down

The ________ design technique can be used to break down an algorithm into functions.

ValueError

The ________ exception is raised when a search item is not in the list being searched.

Scope

The ________ of a local variable is the function in which that variable is created.

min

The __________ function returns the item that has the lowest value in the sequence.

append

The __________ method is commonly used to add items to a list.

reverse

The __________ method reverses the order of the items in a list.

tuple

The ___________ function can be used to convert a list to a tuple.

len

The built-in function __________ returns the length of a sequence.

What of the following describes what happens when a piece of data is written to a file?

The data is copied from a variable in RAM to a file

Which of the following describes what happens when a piece of data is written to a file?

The data is copied from a variable in RAM to a file.

What is a function definition?

The definition (code) that is written to create a function. It specifies what a function does.

True

The difference of set1 and set2 is a set that contains only the elements that appear in set1 but do not appear in set2.

Which of the following doe not apply to sets?

The elements are in pairs.

Which of the following do not apply to sets? The stored elements can be of different data types. All the elements must be unique - no two elements can have the same value. The elements are unordered. The elements are pairs.

The elements are pairs

False

The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs.

If a file does not exist and a program attempts to open it in append mode, what happens?

The file will be created.

What is a priming read? What is its purpose?

The first input operation-just before the loop-is called a priming read, and its purpose is to get the first input value that will be tested by the validation loop.

Header

The first line in a function definition is known as the function

What does the following statement mean? num1, num2 = get_num()

The function get_num() is expected to return a value for num1 and for num2.

What is a priming read? What is it's purpose?

The initial read operation. The purpose is to get the first line in the file, so it can be tested by the loop.

Which part of a dictionary element must be immutable?

The key

What is a control structure?

The logical design which is used to control or handle the execution order of statements.

What is the difference between a class and an instance of a class?

The main difference between a class and an instance of a class is that a class provides a blueprint to the instances for working but is not a real entity. an instance of the class is a real entity which actually uses its definitions and works

True

The major syntax difference between a function and a method is that a method is always associated with an object.

max Function

The max function accepts a sequence, such as a list, as an argument and returns the item that has the highest value in the sequence.

You hear someone make the following comment: "A blueprint is a design for a house. A carpenter can use the blueprint to build the house. If the carpenter wishes, he or she can build several identical houses from the same blueprint." Think of this as a metaphor for classes and objects. Does the blueprint represent a class, or does it represent an object?

The metaphor of a blueprint represents a class.

min Function

The min function accepts a sequence, such as a list, as an argument and returns the item that has the lowest value in the sequence.

What is a user interface?

The part of a computer and its operating system with which the user interacts

What module do you import if you want to pickle objects?

The pickle module

What is the difference between the dictionary methods pop and popitem?

The pop method accepts a key as an argument, returns the value that is associated with that key, and removes that key-value pair from the dictionary. The popitem method returns a randomly selected key-value pair, as a tuple, and removes that key-value pair from the dictionary.

Once a tuple is created, it cannot be changed

The primary difference between a tuple and a list is that

once a tuple is created it cannot be changed

The primary difference between a tuple and a list is that

once a tuple is created, it cannot be changed

The primary difference between a tuple and a list is that

d. once a tuple is created, it cannot be changed

The primary difference between a tuple and list is that _____. a. when creating a tuple you don't use commas to separate elements b. a tuple can only include string elements c. a tuple cannot include lists as elements d. once a tuple is created, it cannot be changed

Methods

The procedures that an object performs are called

Methods

The procedures that an object preforms are called

What is object serialization?

The process of converting the object to a stream of bytes that can be saved to a file for later retrieval.

When the user runs a program in a text-based environment, such as the command line, what determines the order in which things happen?

The program

When a program runs in a text-based environment, such as a command line interface, what determines the order in which things happen?

The program determines the order in which things happen. The command line interface executes based on the command structure.

Replace the underlines with the words in parentheses that follow: The ____ solves the ____ of a ____ by expressing an ____ in a ____ to make a ____ that can run on a ____. algorithm computer problems program programmer programming language user

The programmer solves the problems of a user by expressing an algorithm in a programming language to make a program that can run on a computer.

Give one good reason that you should not use global variables in a program.

The reasons are as follows: • Global variables make debugging difficult. Any statement in a program file can change the value of a global variable. If you find that the wrong value is being stored in a global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. In a program with thousands of lines of code, this can be difficult. • Functions that use global variables are usually dependent on those variables. If you want to use such a function in a different program, most likely you will have to redesign it so it does not rely on the global variable. • Global variables make a program hard to understand. A global variable can be modified by any statement in the program. If you are to understand any part of the program that uses a global variable, you have to be aware of all the other parts of the program that access the global variable.

When the * operator's left operand is a list and its right operand is an integer, the operator becomes this. a. The multiplication operator b. The repetition operator c. The initialization operator d. Nothing-the operator does not support those types of operands.

The repetition operator

Repetition Operator

The repetition operator makes multiple copies of a list and joins them all together. The star symbol is used, when the operand on the left side of the * symbol is a sequence (such as a list) and the operand on the right side is an integer, it becomes a repetition operator.

True

The self parameter is required in every method of a class.

True

The set remove and discard methods behave differently only when a specified item is not found in the set

This is the last index in a list. a. 1 b. 99 c. 0 d. The size of the list minus one

The size of the list minus one

This is the last index in a string. a. 1 b. 99 c. 0 d. The size of the string minus one

The size of the string minus one

Which of the following does not apply to sets?

The stored elements CANNOT be of different types

What is the return value of the string method lstrip()

The string with all leading whitespaces removed

What are a class's responsibilities?

The things that the class is responsible for knowing and the actions that the class is responsible for doing

The typical UML diagram for a class has three sections. What appears in these three sections?

The top section is where you write the name of the class. The middle section holds a list of the class's fields. The bottom section holds a list of the class's methods.

What is a seed value?

The value that initializes a formula. The seed value is used in the calculation that returns the next random number in the series.

What is an accumulator?

The variable used to keep the running total is called an accumulator.

the process of calling a function requires several actions to be performed by the computer. These actions include allocating memory for parameters and local variables and storing the address of the program location where control returns after the function terminates.

These actions, which are sometimes referred to as overhead, take place with each function call. Such overhead is not necessary with a loop.

strip

This sting method returns a copy of the string with all leading and trailing whitespace characters removed.

the isdigit method

This string method returns true if a sting contains only numeric digits and is as least one character in length.

True

To calculate the average of the numeric values in a list, the first step is to get the total of values in the list.

What does the phrase "calling a function" mean?

To execute a function, a function call is required. "Calling a function" is a statement that is used to invoke (execute) the function at required places in a program.

Why should an object's data attributes be hidden from code outside the class?

To secure the data from outside access and unwanted modifications.

The ________ design technique can be used to break down an algorithm into functions.

Top-down

A compound Boolean expression created with the "and" operator is true only when both subexpressions are true. T or F

True

A condition-controlled loop always repeats a specific number of times. T or F

True

A decision structure can be nested inside another decision structure. T or F

True

A dictionary can include the same value several times but cannot include the same key several times. T/F

True

A function in Python can return more than one value. T or F

True

A hierarchy chart does not show the steps that are taken inside a function. T or F

True

A list can be an element in another list. T or F

True

A tuple can be a dictionary key. T or F

True

A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it.

True

An exception handler is a piece of code that is written using the try/except statement.

True

An interpreter is a program that both translates and executes the instructions in a high level language program. T or F

True

Any piece of data that is stored in a computer's memory must be stored as a binary number. T or F

True

Closing a file disconnects the communication between the file and the program.

True

Complex mathematical expressions can sometimes be simplified by breaking out part of the expression and putting it in a function. T or F

True

Dictionaries are not sequences

True

Dictionaries are not sequences. T or F

True

Different functions can have local variables with the same names.

True

Functions make it easier for programmers to work in teams. T or F

True

IPO charts provide only brief descriptions of a function's input, processing, and output, but do not show the specific steps taken in a function. T or F

True

If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences in the paragraph.

True

If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences in the paragraph. T/F

True

If the + operator is used on strings, it produces a string that is a combination of the two strings used as its operands.

True

If the + operator is used on strings, it produces a string that is a combination of the two strings used as its operands. T/F

True

If the last line in a file is not terminated with /n the readline method will return the line without /n.

True

If the last line in a file is not terminated with \n, the readline method will return the line without \n.

True

If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.

True

If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised. A. True B. False

True

If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised. T/F

True

In Python the first character of a variable name cannot be a number. T or F

True

In Python there is nothing that can be done if the program tries to access a file to read that does not exist

True

In Python you can have a list of variables on the left side of the argument operator.

True

In Python, you can specify which parameter an argument should be passed into a function call. T or F

True

In a math expression, multiplication and division takes place before addition and subtraction. T or F

True

In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loop. T or F

True

In order to create graphs using the matplotlib package, you need to import the pyplot module.

True

In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.

True

In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead. T/F

True

Indexing works with both strings and lists.

True

It is possible to create a while loop that determines when the end of a file has been reached.

True

Machine language is the only language that a CPU understands. T or F

True

Main memory is also known as RAM. T or F

True

Object reusability has been a factor in the increased use of object-oriented programming. T or F

True

Once a string is created, it cannot be changed.

True

Once a string is created, it cannot be changed. T or F

True

One reason not to use global variables is that it makes a program hard to debug.

True

One reason to store graphics functions in a module is so that you can import the module into any program that needs to use those functions.

True

Python allows you to pass multiple arguments to a function.

True

Python functions names follow the same rules as those for naming variables

True

Sets store their elements in an unordered fashion. T or F

True

Some library functions are built into the Python interpreter. T or F

True

Starting an attribute name with two underscores will hide the attribute from code outside the class. T or F

True

Strings can be written directly to a file with the write method but numbers must be converted to strings before the can be written.

True

Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.

True

T/F: A class can be thought of as a blueprint that can be used to create an object.

True

T/F: An "is a" relationship exists between a wrench and a tool.

True

T/F: An info dialog box is a window that displays a message to the user and has an OK button which, when clicked, closes the dialog box.

True

T/F: If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.

True

T/F: Object-oriented programming allows us to hide the object's data attributes from code that is outside the object.

True

T/F: Procedures operate on data items that are separate from the procedures.

True

T/F: The difference of set1 and set2 is a set that contains only the elements that appear in set1 but do not appear in set2.

True

T/F: The issubset() method can be used to determine whether set1 is a subset of set2.

True

T/F: The self parameter is required in every method of a class.

True

T/F: The self parameter need not be named self but it is strongly recommended to do so, to conform with standard practice.

True

T/F: The set remove and discard methods behave differently only when a specified item is not found in the set.

True

T/F: You would typically use a for loop to iterate over the elements in a set.

True

The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y if y = 0.

True

The del statement deletes an item at a specified index in a list. T or F

True

The difference of set1 and set2 is a set that contains only the elements that appear in set1 but do not appear in set2.

True

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. False or True

True

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. True and True

True

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. True or False

True

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. True or True

True

The following shows a combination of the values true and false connected by a logical operator. Indicate whether the result of such a combination is true or false. not False

True

The following statement creates an empty dictionary: mydct = { } T or F

True

The following statement subtracts 1 from x: x = x - 1 T or F

True

The function header marks the beginning of the function definition.

True

The index -1 identifies the last character of a string.

True

The index -1 identifies the last element in a list.

True

The issubset() method can be used to determine whether set1 is a subset of set2.

True

The math function ceil(x) returns the smallest integer that is greater than or equal to x.

True

The practice of procedural programming is centered on the creation of objects. T or F

True

The randrange function returns a randomly selected value from a specific sequence of numbers.

True

The remove method raises an exception if the specified element is not found in the set. T or F

True

The repetition operator ( *) works with strings as well as with lists. T or F

True

The repetition operator (*) works with strings as well as lists.

True

The set remove and discard methods behave differently only when a specified item is not found in the set.

True

The set remove and discard methods behave differently only when a specified item is not found in the set. A. True B. False

True

The strip() method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters.

True

The while loop is a pretest loop. T or F

True

To assign a value to a global variable in a function, the global variable must be first declared in the function.

True

To calculate the average of the numeric values in a list, the first step is to get the total of values in the list.

True

True/False the repetition operator(*) works with strings as well as with lists

True

True/False: A class might be thought of as a 'blueprint' that an object may be created from.

True

True/False: An 'IndexError' exception will occur if you try to use an index the is out of range for a particular string.

True

True/False: An exception handler is a piece of code that is written using the try/except statement.

True

True/False: An exception headler is a piece of code that is written using the try/except statement.

True

True/False: Closing a file disconnects the communication between the file and the program

True

True/False: If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences included in the paragraph.

True

True/False: If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.

True

True/False: If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.

True

True/False: If the last line in a file is not terminated with a \n the readline method will return without a \n.

True

True/False: In python strings are immutable which means that once a string has be created it cannot be changed

True

True/False: In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.

True

True/False: In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.

True

True/False: Invalid indexes do not cause slicing expressions to raise an exception.

True

True/False: It is possible to create while loop that determines when the end of a file has been reached.

True

True/False: Lists are dynamic data structures such that items may be added to them or removed from them.

True

True/False: Object-oriented programming allows us to hide the object's data attributes from code that is outside the object.

True

True/False: Once a string is created, it cannot be changed

True

True/False: Procedures operate on data items that are separate from the procedures.

True

True/False: Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written

True

True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.

True

True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero

True

True/False: The first step in calculating the average of the values in a list is to get the total of the values.

True

True/False: The index - 1 identifies the last character in a string.

True

True/False: The issubset method can be used to determine whether set1 is a subset of set2.

True

True/False: The self parameter is required in every method of a class.

True

True/False: The self parameter need not be named self, but it is strongly recommended to conform with standard practice.

True

True/False: You can use the for loop to iterate over the individual characters in a string

True

Tuples in Python are immutable. T or F

True

When an input file is opened, its read position is initially set to the first item in the file. T or F

True

When you open a file that file already exists on the disk using the "w" mode, the contents of the existing file will be erased. T or F

True

You can have more than one except clause in a try/except statement. T or F

True

You can use the + operator to concatenate two lists. T or F

True

You can use the for loop to iterate over the individual characters in a string. T or F

True

You cannot directly call the _ _str_ _ method. T or F

True

You would typically use a for loop to iterate over the elements in a set.

True

True

True/False: An exception handler is a piece of code that is written using the try/except statement.

False

True/False: Arrays, which most other programming languages allow, have much more capabilities than list structures.

True

True/False: Closing a file disconnects the communication between the file and the program.

False

True/False: If a file with the specified name already exists when the file is opened, and the file is opened in 'w' mode, then an alert will appear on the screen.

True

True/False: If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.

False

True/False: In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.

True

True/False: In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.

False

True/False: Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.

True

True/False: It is possible to create a while loop that determines when the end of a file has been reached.

False

True/False: Python allows the programmer to work with text and number files.

True

True/False: Sets are created using curly braces {}.

False

True/False: Sets are immutable.

True

True/False: Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.

True

True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.

True

True/False: The first step in calculating the average of the values in a list is to get the total of the values.

True

True/False: The index - 1 identifies the last element in a list

False

True/False: The index of the first element in a set is 0.

False

True/False: The index of the first key-value pair in a dictionary is 0.

True

True/False: The issubset method can be used to determine whether set1 is a subset of set2.

True

True/False: The set remove and discard methods behave differently only when a specified item is not found in the set.

False

True/False: The sort method rearranges the elements of a list so they appear in ascending or descending order.

False

True/False: When a piece of data is read from a file, it is copied from the file into the program.

Which method can be used to convert a list to a tuple?

Tuple

The primary difference between a tuple and a list is that

Tuple immutable, once created can't be changed

immutable

Tuples are __________ sequences which means that once a tuple is created, it cannot be changed.

A Tuple does not support what methods?

Tuples do not support methods such as append, remove, insert, reverse, and sort.

An extensive encoding scheme that can represent characters for many languages in the world is __________ a. binary numbering b. ASCII c. Unicode d. ENIAC

Unicode

What does the acronym UML stand for?

Unified Modeling Language

What does the acronym UML stand for? a. Unified Modeling Language b. United Modeling Language c. Unified Model Language d. Union of Modeling Languages

Unified Modeling Language

Are the elements of a set ordered or unordered?

Unordered

How do you find the length of a string?

Use the len( ) function

The _______________ exception is raised when a search item is not in the list being searched.

ValueError

What type of exception does a program raise when it uses the float function to convert a non-numeric string to a number?

ValueError

class Celery(Vegetable) :

Vegetable

elements

What are the data items in a list called

Elements

What are the data items in a list called?

elements

What are the data items in a list called?

b. elements

What are the data items in the list called? a. data b. elements c. items d. values

0 through 7

What are the valid indexes for the string 'New York'?

a. 0 through 7

What are the valid indexes for the string 'New York'? a. 0 through 7 b. 0 through 8 c. -1 through -8 d. -1 through 6

b. Reading data

What do you call the process of retrieving data from a file? a. Retrieving data b. Reading data c. Input data d. Get data

Unified Modeling Language

What does the acronym UML stand for?

Unified Modeling Language

What does the acronym UML stands for?

it returns a default value

What does the get method do if the specified key is not found in the dictionary?

a. Data is copied from a variable in RAM to a file.

What happens when a piece of data is written to a file? a. Data is copied from a variable in RAM to a file. b. Data is copied from a variable in the program to a file. c. Data is copied from the program to a file. d. Data is copied from a file object to a file.

A function

What is a group of statements that exists within a program for the purpose of performing a specific task?

Processing a tuple is faster than processing a list.

What is an advantage of using a tuple rather than a list?

processing a tuple is faster

What is an advantage of using a tuple rather than a list?

Processing a tuple is faster than processing a list

What is an an advantage of using a tuple rather than a list?

c. Processing a tuple is faster than processing a list.

What is the advantage of using tuples over lists? a. Tuples are not limited in size. b. Tuples can include any data type as an element. c. Processing a tuple is faster than processing a list. d. There is no advantage.

b. { 1 : 'January', 2 : 'February', 3 : 'March' }

What is the correct structure for creating a dictionary of month names to be accessed by month numbers? a. { 1 ; 'January', 2 ; 'February', 3 ; 'March' } b. { 1 : 'January', 2 : 'February', 3 : 'March' } c. [ 1 : 'January', 2 : 'February', 3 : 'March' ] d. { 1, 2, 3 : 'January', 'February', 'March' }

{ 1 : 'January', 2 : 'February', ... 12 : 'December' }

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)?

b. -1

What is the first negative index in a string? a. 0 b. -1 c. -0 d. Size of the string minus one

Dictionaries are not indexed by number.

What is the number of the first index in a dictionary?

is a

What is the relationship called in which one object is a specialized version of another object?

d. The string with all leading whitespaces removed

What is the return value of the string method lstrip()? a. The string with all whitespace removed b. The string with all leading spaces removed c. The string with all leading tabs removed d. The string with all leading whitespaces removed

b. {'John': '1234567', 'Julie' : '7777777'}

What is the value of the variable phones after the execution of the following code? phones = {'John': '5555555', 'Julie' : '7777777'} phones['John'] = '1234567' a. {'John': '5555555', 'Julie' : '7777777'} b. {'John': '1234567', 'Julie' : '7777777'} c. {'John': '1234567' } d. invalid code

{'John' : '5556666', 'Julie' : '5557777'}

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = 5556666'

c. 'Hello world'

What is the value of the variable string after the execution of the following code? string = 'Hello' string += ' world' a. 'Hello' b. ' world' c. 'Hello world' d. Invalid code

c. 'ABCD'

What is the value of the variable string after the execution of the following code? string = 'abcd' string.upper() a. 'abcd' b. 'Abcd' c. 'ABCD' d. Invalid code

c. update

What method can be used to add a group of elements to a set? a. add b. addgroup c. update d. Elements must be added one at a time.

b. tuple

What method can be used to convert a list to a tuple? a. append b. tuple c. insert d. list

d. list

What method can be used to convert a tuple to a list? a. append b. tuple c. insert d. list

c. insert

What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add

b. +

What method or operator can be used to concatenate lists? a. * b. + c. % d. concat

c. try/except statement

What statement can be used to handle some of the run-time errors in a program? a. exception statement b. try statement c. try/except statement d. exception handler statement

b. Random

What type of file access jumps directly to any piece of data in a file without reading the data that came before it? a. Sequential b. Random c. Number d. Text

Boolean

What type of function can be used to determine whether a number is even or odd?

accessor

What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method?

Accessor

What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by cose outside the method?

Object-oriented

What type of programming contains class definitions?

object-oriented

What type of programming contains class definitions?

b. '1357'

What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special[ :4] a. '7' b. '1357' c. '1357 ' d. Invalid code

b. 'Ln.'

What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special[-3: ] a. '531' b. 'Ln.' c. ' Ln.' d. '7531'

c. ' Country Ln.'

What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special[4: ] a. '1357' b. 'Country Ln.' c. ' Country Ln.' d. Invalid code

c. '02468'

What will be assigned to the string variable even after the execution of the following code? special = '0123456789' even = special[0:10:2] a. '13579' b. '2468' c. '02468' d. Invalid code

a. 'zzzzzzzzzzzzzzz'

What will be assigned to the string variable pattern after the execution of the following code? i = 3 pattern = z x (5 x i) a. 'zzzzzzzzzzzzzzz' b. 'zzzzz' c. Error: '*' operator used incorrectly d. The right side of the '*' must be an integer

'1357'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4]

'Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:]

'County Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:]

02468

What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2]

{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities)

{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)

{'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)

KeyError

What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna']

[1, 2, 1, 2, 1, 2]

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list=list * 3

[1, 2, 10, 4]

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[2] = 10

[1, 2, 3, 10]

What will be the value of the variable list after the following code executes?list = [1, 2, 3, 4] list[3] = 10

"Hello world"

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!

a. [1, 2, 3, 10]

What would be the value of the variable list after the execution of the following code? list = [1, 2, 3, 4] list[3] = 10 a. [1, 2, 3, 10] b. [1, 2, 10, 4] c. [1, 10, 10, 10] d. invalid code

c. [1, 2, 1, 2, 1, 2]

What would be the value of the variable list after the execution of the following code? list = [1, 2] list = list * 3 a. [1, 2] * 3 b. [3, 6] c. [1, 2, 1, 2, 1, 2] d. [[1, 2], [1, 2], [1, 2]]

a. [1, 2, 3]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = [] for element in list1 list2.append(element) list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code

b. [4, 5, 6]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = list1 list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code

a. del statement

What would you use if an element is to be removed from a specific index? a. del statement b. remove method c. index method d. slice method

d. read

When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string? a. write b. input c. get d. read

read

When a file has been opened using the 'r' mode specifier, which method will return the file's whole contents as a string?

Executed

When a function is called by its name during the execution of a program, then it is

What is the purpose of the self parameter in a method?

When a method executes, it must have a way of knowing which object's data attributes it is supposed to operate on. That's where the self parameter comes in. When a method is called, Python automatically makes its self parameter reference the specific object that the method is supposed to operate on.

How can functions make it easier for programs to be developed by teams of programmers?

When a program is developed as a set of functions that each performs an individual task, then different programmers can be assigned the job of writing different functions.

When one object is a specialized version of another object, there is an " is a" relationship between them.

When an "is a" relationship exists between objects, it means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special.

A reference of the object

When an object is passed as an argument, ______ is passed into the parameter variable.

Why is an object's internal data usually hidden from outside code?

When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption. In addition, the programming code outside the object does not need to know about the format or internal structure of the object's data.

output

When data is written to a file, it is described as a(n) ________ file.

What does it mean to say there is an "is a" relationship between two objects?

When one object is a specialized version of another object, there is an "is a" relationship between them. The specialized object " is a" version of the general object.

What is the advantage of using a sentinel?

When processing a long sequence of values with a loop, a better technique is to use a sentinel. A sentinel is a special value that marks the end of a sequence of items. When a program reads the sentinel value, it knows it has reached the end of the sequence, so the loop terminates.

When a function is executing, what happens when the end of the function's block is reached?

When the end of the block is reached, the interpreter jumps back to the part of the program that called the function, and the program resumes execution at that point. When this happens, we say that the function "returns".

When you write an if-else statement, under what circumstances do the statements that appear after the else clause execute?

When the if condition is false the program follows the else clause.

False

When the read method is used to read data from an non-existing file, an empty string will be returned to the program.

False

When the write method is used to write data into an non-existing file, an alert will be raised.

Nested list

When working with multiple sets of data, one would typically use a(n)

nested list

When working with multiple sets of data, one would typically use a(n)

c. nested list

When working with multiple sets of data, one would typically use a(n) _____. a. list b. tuple c. nested list d. Sequence

nested list

When working with multiple sets of data, one would typically use a(n) ________.

instance

Which attributes belong to a specific instance of a class?

c. len

Which function would you use to get the number of elements in a dictionary? a. size b. length c. len d. invalid code

class Worker:

Which is the first line needed when creating a class named Worker?

b. ['03', '07', '2008']

Which list will be referenced by the variable list_strip after the execution of the following code? list_string = '03/07/2008' list_strip = list_string.split('/') a. ['3', '7', '2008'] b. ['03', '07', '2008'] c. ['3', '/', '7', '/', '2008'] d. ['03', '/', '07', '/', '2008']

Update

Which method can be used to add a group of elements to a set?

Tuple

Which method can be used to convert a list to a tuple?

tuple

Which method can be used to convert a list to a tuple?

List

Which method can be used to convert a tuple to a list?

list

Which method can be used to convert a tuple to a list?

insert

Which method can be used to place an item at a specific index in a list

Insert

Which method can be used to place an item at a specific index in a list?

insert

Which method can be used to place an item at a specific index in a list?

isinstance

Which method can you use to determine whether an object is an instance of a class?

str

Which method could be used to convert a numeric value to a string?

a. str

Which method could be used to convert a numeric value to a string? a. str b. value c. num d. chr

rstrip

Which method could be used to strip specific characters from the end of a string?

b. rstrip

Which method could be used to strip specific characters from the end of a string? a. estrip b. rstrip c. strip d. remove

__str__

Which method is automatically called when you pass an object as an argument to the print function?

+ (Plus sign)

Which method or operator can be used to concatenate lists?

readline

Which method will return an empty string when it has attempted to read beyond the end of a file?

d. readline

Which method will return an empty string when it has attempted to read beyond the end of a file? a. Read b. Getline c. input d. readline

find(substring)

Which method would you use to determine wether a certain substring is present in a string?

endswith(substring)

Which method would you use to determine wether a certain substring is the suffix of a string?

b. find(substring)

Which method would you use to determine whether a substring is present in a string? a. endswith(substring) b. find(substring) c. replace(string, substring) d. startswith(substring)

a. endswith(substring)

Which method would you use to determine whether a substring is the suffix of a string? a. endswith(substring) b. find(substring) c. replace(string, substring) d. startswith(substring)

Items

Which method would you use to get all the elements in a dictionary returned as a list of tuples?

items

Which method would you use to get all the elements in a dictionary returned as a list of tuples?

Pop

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

pop

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

d. pop

Which method would you use to return the value associated with a specified key and remove that key-value pair from the dictionary? a. list b. items c. popitem d. pop

b. items

Which method would you use to returns all the elements in the dictionary as a list of tuples? a. list b. items c. pop d. keys

a. 'w'

Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist? a. 'w' b. 'r' c. 'a' d. 'e'

'w'

Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist?

'r'

Which mode specifier will open a file but not let you change the file or write to it?

b. 'r'

Which mode specifier will open a file but will not let you change the file or write to it? a. 'w' b. 'r' c. 'a' d. 'e'

An object

Which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate on the data attributes?

an object

Which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate on the data attributes?

The elements are in pairs.

Which of the following does not apply to sets?

d. The elements are pairs.

Which of the following does not apply to sets? a. The stored elements can be of different data types. b. All the elements must be unique - no two elements can have the same value. c. The elements are unordered. d. The elements are pairs.

the file object

Which of the following is associated with a specific file and provides a way for the program to work with that file?

class table(furniture):

Which of the following is the correct syntax for defining a class, table, which inherits from the furniture class?

infile = open('r', users.txt)

Which of the following is the correct way to open a file named users.txt in 'r' mode?

outfile = open('users.txt', 'w')

Which of the following is the correct way to open a file named users.txt to write to it?

Import random

Which of the following statements causes the interpreter to load the contents of the random module into memory?

d. isspace()

Which of the following string methods can be used to determine if a string contains only '\n' characters? a. ischar() b. isalpha() c. istab() d. isspace()

worker_joey = Worker()

Which of the following will create an object, worker_joey, of the Worker class?

A del statement

Which of the following would you use if an element is to be removed from a specific index?

a del statement

Which of the following would you use if an element is to be removed from a specific index?

the del statement

Which of the following would you use if an element is to be removed from a specific index?

c. File object

Which of these is associated with a specific file and provides a way for the program to work with that file? a. Filename b. Extension c. File object d. File variable

Second section

Which section in the UML holds the list of the class's data attributes?

second section

Which section in the UML holds the list of the class's data attributes?

Third section

Which section in the UML holds the list of the class's methods?

third section

Which section in the UML holds the list of the class's methods?

a. del

Which statement would you use to delete an existing key-value pair from a dictionary? a. del b. remove c. delete d. unpair

open the file

Which step creates a connection between a file and a program?

a. Open the file.

Which step creates a connection between a file and a program? a. Open the file. b. Read the file. c. Process the file. d. Close the file.

Del

Which would you use to delete an existing key-value pair from a dictionary?

del

Which would you use to delete an existing key-value pair from a dictionary?

Len

Which would you use to get the number of elements in a dictionary?

len

Which would you use to get the number of elements in a dictionary?

Should an accumulator be initialized to any specific value? Why or why not?

Yes, to 0. the first step is to set the accumulator variable to 0. This is a critical step. Each time the loop reads a number, it adds it to the accumulator. If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.

Is it permissible for a local variable in one function to have the same name as a local variable in a different function?

Yes; Different functions can have local variables with the same names because the functions cannot see each other's local variables.

How do you create an empty set?

You call the built-in set function.

RAM, random-access memory, is called that because: a. it is optimized for random number processing. b. accesses are randomized to prevent clogging the control lines. c. you can pick any two random locations and it will take the same time to access the data. d. when power is turned off, its contents are lost and replaced by random bits. e. none of the above.

You can pick any two random locations and it will take the same time to access the data.

How can you determine whether a key-value pair exists in a dictionary?

You can use the in operator to test for a specific key.

How can you determine whether a specific element exists in a set?

You can use the in operator to test for the element.

Describe the way that you use a temporary file in a program that modifies a record in a sequential access file.

You copy all of the original file's records to the temporary file, but when you get to the record that is to be modified, you do not write its old contents to the temporary file. Instead, you write its new modified values to the temporary file. Then, you finish copying any remaining records from the original file to the temporary file. The temporary file then takes the place of the original file. You delete the original file and rename the temporary file, giving it the name that the original file had on the computer's disk.

Describe the way that you use a temporary file in a program that deletes a record from a sequential file.

You copy all of the original file's records to the temporary file, except for the record that is to be deleted. The temporary file then takes the place of the original file. You delete the original file and rename the temporary file, giving it the name that the original file had on the computer's disk.

a. String comparisons are case sensitive so 'jimmy' does not equal 'Jimmy'.

You created the following dictionary relationships = {'Jimmy':'brother'}. You then executed the following code, and received a KeyError exception. What is the reason for the exception? relationships['jimmy'] a. String comparisons are case sensitive so 'jimmy' does not equal 'Jimmy'. b. You used the wrong syntax for creating the dictionary. c. You should have used the code relationships['brother']. d. There is a bug in Python.

How do you determine the number of elements in a set?

You pass the set as an argument to the len function.

What is the purpose of opening a file?

You use the open function in Python to open a file. The open function creates a file object and associates it with a file on the disk.

True

You would typically use a for loop to iterate over the elements in a set.

You want the user to be able to select any number of items from a group of items. Which type of component would you use for the items, radio buttons or check boxes?

You would use check buttons.

You want the user to be able to select only one item from a group of items. Which type of component would you use for the items, radio buttons or check boxes?

You would use radio buttons.

Which list will be referenced by the variable number after the execution of the following code? number = list ( range (0, 9, 2) )

[0, 2, 4, 6, 8]

what will be the value of the variable list2 after the following code executes? list1=[1, 2 , 3] list2=[] for element in list1: list2.append(element) list1=[4, 5 , 6]

[1 , 2, 3] explanation : list one will print becasue list 2 has nothing and bottom list1 is to confuse you

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = [] for element in list1 list2.append(element) list1 = [4, 5, 6] [1, 2, 3] [4, 5, 6] [1, 2, 3, 4, 5, 6] invalid code

[1, 2 ,3]

What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3

[1, 2, 1, 2, 1, 2]

What would be the value of the variable list after the execution of the following code? list = [1, 2] list = list * 3

[1, 2, 1, 2, 1, 2]

What would be the value of the variable list after the execution of the following code? list = [1, 2] list = list * 3 [1, 2] * 3 [3, 6] [1, 2, 1, 2, 1, 2] [[1, 2], [1, 2], [1, 2]]

[1, 2, 1, 2, 1, 2]

What would be the value of the variable list after the execution of the following code? list=[1,2] list=list*3

[1, 2, 1, 2, 1, 2]

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10

[1, 2, 3, 10]

What would be the value of the variable list after the execution of the following code? list = [1, 2, 3, 4] list[3] = 10

[1, 2, 3, 10]

What would be the value of the variable list after the execution of the following code? list=[1,2,3,4] list[3]=10

[1, 2, 3, 10]

What would be the value of the variable list after the execution of the following code?list = [1, 2, 3, 4] list[3] = 10 [1, 2, 3, 10] [1, 2, 10, 4] [1, 10, 10, 10] invalid code

[1, 2, 3, 10]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6]

[1, 2, 3]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = [] for element in list1 list2.append(element) list1 = [4, 5, 6]

[1, 2, 3]

What will be the value of the variable list after the following code executes? list=[1,2] list=list*3

[1,2,1,2,1,2]

What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3

[1,2,1,2,1,2]

What will be the value of the variable list after the following code executes? list=[1,2,3,4] list[3]=10

[1,2,3,10]

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10

[1,2,3,10]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = list1 list1 = [4, 5, 6]

[4, 5, 6]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = list1 list1 = [4, 5, 6] [1, 2, 3] [4, 5, 6] [1, 2, 3, 4, 5, 6] invalid code

[4, 5, 6]

What would be the value of the variable list2 after the execution of the following code? list1=[1,2,3] list2=list1 list1=[4,5,6]

[4,5,6]

What does the following code display? numbers = [ 1, 2, 3, 4, 5, 6, 7] print(numbers[4:6])

[5, 6]

The character escape sequence to represent a double quote is:

\"

The character escape sequence to represent a single quote is:

\'

The character escape sequence to represent a backslash is:

\\

The character escape sequence to force the cursor to go to the next line is:

\n

The character escape sequence to force the cursor to advance forward to the next tab setting is:

\t

This operator can be used to find the symmetric difference of two sets. a. I b. & c. - d. ^

^

this operator can be used to find the symmetric difference of two sets

^

list

__________ is the type of object that holds multiple items of data.

Which of the following IS a legal identifier? a. 5_And_10 b. Five_&_Ten c. ____________ d. LovePotion#9 e. "Hello World"

____________ Correct - Weird, but valid.

Which method is automatically called when you pass an object as an argument to the PRINT function

____str____

Which method is automatically executed when an instance of the class is created in memory?

__init__

What is the special name given to the method that returns a string containing the object's state?

__str__

Which of the following would you use if an element is to be removed from a specific statemtn

a DEL statement

Which statements can be used to handle some of the routine errors in a program?

a TRY/EXCEPT PROGRAM

A bit is a. a metallic rod inserted into a horses mouth to control it while riding. b. a small amount of data. c. an alternative term for byte. d. an electronic device used in computers. e. a binary digit, like 0 or 1.

a binary digit, like 0 or 1

len Function

a built-in function that returns the length of a sequence, such as a list.

What is a record?

a complete set of data about an item

Which of the following would you use if an element is to be removed from a specific index?

a del statement

What is an input file?

a file that data is read from. It is called an input file because the program gets input from the file.

What is an output file?

a file that data is written to. It is called an output file because the program stores output in it.

What is a value-returning function?

a function that returns a value back to the part of the program that called it.

A value-returning function is

a function that will return a value back to the part of the program that called it

A value-returning function is..

a function that will return a value back to the part of the program that called it.

What is a Boolean function?

a function which returns either True or False. You can use a Boolean function to test a condition, and then return either True or False to indicate whether the condition exists. Boolean functions are useful for simplifying complex conditions that are tested in decision and repetition structures.

What is a global constant?

a global name that references a value that cannot be changed.

What is the primary difference between a list and a tuple?

a list is mutable, which means that a program can change its contents. a tuple is immutable, which means that once it is created, its contents cannot be changed.

two-dimensional list (nested lists)

a list that has other lists as its elements.

What is a library function?

a prewritten function that performs commonly needed tasks. Python, as well as most other programming languages, comes with a standard library of functions that have already been written for you. These functions, known as library functions, make a programmer's job easier because they perform many of the tasks that programmers commonly need to perform.

What is the difference between sequential access and direct access files?

a sequential access file, you access data from the beginning of the file to the end of the file. If you want to read a piece of data that is stored at the very end of the file, you have to read all of the data that comes before it - you cannot jump directly to the desired data. a direct access file (which is also known as a random access file), you can jump directly to any piece of data in the file without reading the data that comes before it

If you were to look at a machine language program, you would see __________ a. Python code b. a stream of binary numbers c. English words d. circuits

a stream of binary

Which statement can be used to handle some of the runtime errors in a program?

a try/except statement

What would be the value of the variable list after the execution of the following code? list = [1, 2, 3, 4] list[3] = 10 a. [1, 2, 3, 10] b. [1, 2, 10, 4] c. [1, 10, 10, 10] d. invalid code

a. [1, 2, 3, 10]

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = [] for element in list1 list2.append(element) list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code

a. [1, 2, 3]

What would you use if an element is to be removed from a specific index? a. del statement b. remove method c. index method d. slice method

a. del statement

A(n) method gets the value of a data attribute but does not change it. a. retriever b. constructor c. mutator d. accessor

accessor

What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method? a. accessor b. mutator c. setter d. class

accessor

What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that they could be changed by the code outside the method?

accessor

*A(n) _______ variable keeps a running total. a. sentinel b. sum c. total d. accumulator

accumulator

To add a single item to a set, you can use the set method _______________.

add

You can add one element to a set with this method

add

You can add one element to a set with this method. a. append b. add c. update d. merge

add

A byte in memory is identified by a unique number called its _______.

address

KeyError

ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna']

A(n) _______ is a set of well-defined logical steps that must be taken to perform a task. a. logarithm b. plan of action c. logic schedule d. algorithm

algorithm

An operating system a. is the chief hardware unit in a computer. b. is loaded into the computer each time it needs to carry out an operation. c. ensures that programs will not run on the computer at the same time. d. allocates resources like memory to programs that are running. e. all of the above.

allocates resources like memory to programs that are running.

Briefly describe what an exception is.

an error that occurs while a program is running

What is a field?

an individual piece of data within a record

A component that collects data from people or other devices and sends it to the computer is called __________ a. an output device b. an input device c. a secondary storage device d. main memory

an input device

At each step of its operation, the input to a Central Processing Unit is: a. a program. b. an instruction. c. main memory. d. a control unit.

an instruction

which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate o the data attributes

an object

Sequence

an object that holds multiple items of data, stored one after the other. You can perform operations on a sequence to examine and manipulate the items stored in it.

What is a file object?

an object that is associated with a specific file and provides a way for the program to work with that file.

A compound Boolean expression created with the _____ operator is true only if both of its subexpressions are true. a. and b. or c. not d. both

and

When determining whether a number is inside a range, which logical operator is it best to use?

and

Explain how short-circuit evaluation works with the "and" and "or" operators.

and operator short circuit - If the left sub expression is false then it will not check the right sub expression because the overall expression has already been determined as false. or operator short circuit - If the left sub expression is true then it will not check the right sub expression because the overall expression has already been determined as true.

This list method adds an item to the end of an existing list. a. add b. add to c. increase d. append

append

When a file is opened in this mode, data will be written at the end of the file's existing contents. a. output mode b. append mode c. backup mode d. read-only mode

append mode

A(n) _______ is a piece of data that is sent into a function. a. argument b. parameter c. header d. packet

argument

What are the pieces of data that are passed into a function called?

arguments

The following statements call a function named show_data. Which of the statements passes arguments by position, and which passes keyword arguments? a. show_data ( name= 'Kathryn' , age=25 ) b. show_ data ( 'Kathryn' , 25 )

arguments by position: show_ data ( 'Kathryn' , 25 ) keyword arguments: show_data ( name= 'Kathryn' , age=25 )

This ___________ translates an assembly language program to a machine language program. a. assembler b. compiler c. translator d. interpreter

assembler

A(n) _______ makes a variable reference a value in the computer's memory. a. variable declaration b. assignment statement c. math expression d. string literal

assignment statement

The -= operator is an example of a(n) _______ operator. a. relational b. augmented assignment c. complex assignment d. reverse assignment

augmented assignment

What method or operator can be used to concatenate lists? a. * b. + c. % d. concat

b. +

What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = list1 list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code

b. [4, 5, 6]

What are the data items in the list called? a. data b. elements c. items d. values

b. elements

What method can be used to convert a list to a tuple? a. append b. tuple c. insert d. list

b. tuple

By doing this you can hide a class's attribute from code outside the class. a. avoid using the self parameter to create the attribute b. begin the attribute's name with two underscores c. begin the name of the attribute with private _ _ d. begin the name of the attribute with the @ symbol

begin the attribute's name with two underscores

In the __________ numbering system, all numeric values are written as sequences of Os and 1s. a. hexadecimal b. binary c. octal d. decimal

binary

This type of file contains data that has not been converted to text. a. text file b. binary file c. Unicode file d. symbolic file

binary file

A byte is made up of eight __________ a. CPUs b. instructions c. variables d. bits

bits

This is a small "holding section " in memory that many systems write data to before writing the data to a file. a. buffer b. variable c. virtual file d. temporary file

buffer

If a class has a method named _ _str_ _, which of these is a way to call the method? a. you call it like any other method: object.._ _str_ _( ) b. by passing an instance of the class to the built in str function c. the method is automatically called when the object is created d. by passing an instance of the class to the built-in state function

by passing an instance of the class to the built in str function

How do you find the lowest and highest values in a list?

by using the min and/or the max functions

A __________ is enough memory to store a letter of the alphabet or a small number. a. byte b. bit c. switch d. transistor

byte

What is the advantage of using tuples over lists? a. Tuples are not limited in size. b. Tuples can include any data type as an element. c. Processing a tuple is faster than processing a list. d. There is no advantage.

c. Processing a tuple is faster than processing a list.

What would be the value of the variable list after the execution of the following code? list = [1, 2] list = list * 3 a. [1, 2] * 3 b. [3, 6] c. [1, 2, 1, 2, 1, 2] d. [[1, 2], [1, 2], [1, 2]]

c. [1, 2, 1, 2, 1, 2]

What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add

c. insert

When working with multiple sets of data, one would typically use a(n) _____. a. list b. tuple c. nested list d. Sequence

c. nested list

You _______ the function to execute it. a. define b. call c. import d. export

call

A(n) ______ is a function or method that is called when a specific event occurs. a. callback function b. auto function c. startup function d. exception

callback function

in Operator

can be used to determine whether an item is contained in a list.

case-insensitive

case of character is ignored

class Beverage:......

class Cola(Beverage): def__init__(self): Beverage.__init__(self,'cola') hing the word "self" is the give away in this answer

Which of the following is the correct syntax for defining a class, TABLE, which inherits from the FURNITURE class

class table (furniture) :

The _______________ method clears the contents of a dictionary

clear

When a program is finished using a file, it should do this. a. erase the file b. open the file c. close the file d. encrypt the file

close the file

A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is _______. a. code reuse b. divide and conquer c. debugging d. facilitation of teamwork

code reuse

Before GUis became popular, the _______ interface was the most commonly used. a. command line b. remote terminal c. sensory d. event-driven

command line

Short notes placed in different parts of a program explaining how those parts of the program work are called _______. a. comments b. reference manuals c. tutorials d. external documentation

comments

append(item) Method

commonly used to add items to a list. The item that is passed as an argument is appended to the end of the list's existing elements.

An error in a program that involves a violation of language rules will be detected at _______ time.

compile

A(n) _________ program translates a high-level language program into a separate machine language program. a. assembler b. compiler c. translator d. utility

compiler

appending one string to the end of another string

concatenation

A _______-controlled loop uses a true/false condition to control the number of times that it repeats. a. Boolean b. condition c. decision d. count

condition

A _______-controlled loop repeats a specific number of times. a. Boolean b. condition c. decision d. count

count

Assume that the customer file references a file object, and the file was opened using the 'w' mode specifier. How would you write Mary Smith in the file

customer.write('Mary Smith')

Given that the customer file references a file object, and the file was opened using the 'w' mode specifier how would you write the strong 'Mary Smith' to the file?

customer.write('Mary Smith')

Given that the customer file references a file object, and the file was opened using the 'w' mode specifier, how would you write the string 'Mary Smith' to the file?

customer.write('Mary Smith')

Which list will be referenced by the variable number after the execution of the following code? number = range(0, 9, 2) a. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] b. [1, 3, 5, 7, 9] c. [2, 4, 6, 8] d. [0, 2, 4, 6, 8]

d. [0, 2, 4, 6, 8]

What method can be used to convert a tuple to a list? a. append b. tuple c. insert d. list

d. list

The primary difference between a tuple and list is that _____. a. when creating a tuple you don't use commas to separate elements b. a tuple can only include string elements c. a tuple cannot include lists as elements d. once a tuple is created, it cannot be changed

d. once a tuple is created, it cannot be changed

A(n) _______ is a component of a class that references data. a. method b. instance c. data attribute d. module

data attribute

Assume the variable name, date_string contains 31-12-1995. Using proper codes related to string, list, and print, produce the following three-line output (4 statements only): Month = 12 Day = 31 Year =1995

date_list=[] date_string='31-12-1995' date_list = date_string.split('-') print('Month:',date_list[1],'\nDate:',date_list[0],'\nYear:'date_list[2])

A _____ structure can execute a set of statements only under certain circumstances. a. sequence b. circumstantial c. decision d. Boolean

decision

In the __________ part of the fetch-decode-execute cycle, the CPU determines which operation it should perform. a. fetch b. decode c. execute d. immediately after the instruction is executed

decode

Which statement would you use to delete an existing key-value pair from a dictionary? del remove delete unpair

del

Which would you use to delete an existing key-value pair from a dictionary? A. delete B. del C. remove D. unpair

del

Which would you use to delete an existing key-value pair from a dictionary? delete del remove unpair

del

You use ___ to delete an element from a dictionary

del

Which would you use to delete an existing key-value pair from a dictionary?

del dictionary[key]

In a dictionary, what would you use if an element is to be removed from a specific index?

del statement

What would you use if an element is to be removed from a specific index?

del statement

What would you use if an element is to be removed from a specific index? del statement remove method index method slice method

del statement

What would you use if an element is to be removed from a specific index? a. del statement b. [1, 3, 5, 7, 9] c. index method d. slice method

del statement

'not' operator

determine whether one string is not contained in another string

A _______ is a small window that displays information and allows the user to perform actions. a. menu b. confirmation window c. startup screen d. dialog box

dialog box

A ______ is an object that stores a collection of data. Each element in a dictionary has two parts: a key and a value. You use a key to locate a specific value.

dictionary

When working with this type of file, you can jump directly to any piece of data in the file without reading the data that comes before it. a. ordered access b. binary access c. direct access d. sequential access

direct access

This set method removes an element but does not raise an exception if the element is not found. a. remove b. discard c. delete d. erase

discard

This set method removes an element but does not raise an exception if the element is not found

discard

A(n) _____ structure tests a condition and then takes one path if the condition is true, or another path if the condition is false. a. if statement b. single alternative decision c. dual alternative decision d. sequence

dual alternative decision

repetition (*) operator

duplicate a string

A string literal in Python must be enclosed in a. parentheses. b. single-quotes. c. double-quotes. d. either single-quotes or double-quotes.

either single-quotes or double-quotes

This term refers to an individual item in a list. a. element b. bin c. cubbyhole d. slot

element

What are the data items in the list called?

elements

What are the data items in the list called? data elements items values

elements

What is the combining of data and code in a single object known as?

encapsulation

The substring argument is a string. The method returns true if the string ends with substring.

endswith(substring)

Which method would you use to determine whether a certain substring is the suffix of a string? startswith(substring) find(substring) replace(string, substring) endswith(substring)

endswith(substring)

Which method would you use to determine whether a substring is the suffix of a string?

endswith(substring)

Which method would you use to determine whether a certain substring is the suffix of a string?

endwith(substring)

What is a traceback?

error message that gives information regarding the line number(s) that caused the exception

Validation loops are also known as: a. error traps. b. doomsday loops. c. error avoidance loops. d. defensive loops.

error traps

This is a section of code that gracefully responds to exceptions. a. exception generator b. exception manipulator c. exception handler d. exception monitor

exception handler

Arrays, which most other programming languages allow, have much more capabilities than list structures.

false

The math function, atan (x) returns one tangent of x in radians.

false

The sort method rearranges the elements of a list so they appear in ascending or descending order.

false

True/False: Python allows the programmer to work with text and number files

false

string[i]='i'

false

the dictionary method popitem does not raise an exception if it is called on an empty dictionary

false

you can store duplicate items in a set

false

This is a single piece of data within a record. a. field b. variable c. delimiter d. subrecord

field

When a program needs to save data for later use, it writes the data in a(n) _______________.

file

Which of these is associated with a specific file and provides a way for the program to work with that file?

file object

When writing a program that performs an operation on a file, what two file associated names do you have to work with in your code?

file_variable and filename file_variable is the name of the variable that will reference the file object. filename is a string specifying the name of the file.

The substring argument is a string. The method returns the lowest index in the string where substring is found. If substring is not found, the method returns -1.

find(substring)

Which method would you use to determine whether a certain substring is present in a string?

find(substring)

Which method would you use to determine whether a certain substring is present in a string? endswith(substring) find(substring) startswith(substring) replace(string, substring)

find(substring)

Which method would you use to determine whether a substring is present in a string?

find(substring)

A _____ is a Boolean variable that signals when some condition exists in the program. a. flag b. signal c. sentinel d. siren

flag

Suppose the following statement is in a program: price = 99. 0. After this statement executes, the price variable will reference a value of this data type. a. int b. float c. currency d. str

float

If a math expression adds a float to an int, what will the data type of the result be?

float data type

This built-in function can be used to convert an int value to a float. a. int_to_float() b. float() c. convert ( ) d. int()

float()

Real numbers are encoded using the _______ technique. a. two's complement b. floating point c. ASCII d. Unicode

floating point

A _______ is a diagram that graphically depicts the steps that take place in a program. a. flowchart b. step chart c. code graph d. program graph

flowchart

One of the easiest ways to access the individual characters in a string is to use the____________

for loop

Assume namesList contains a list of names (as strings). Write a for-loop that walks over the list and prints out all the names.

for n in namesList: print(n)

A group of statements that exist within a program for the purpose of performing a specific task is a(n) _______. a. block b. parameter c. function d. expression

function

GIGO stands for a. great input, great output b. garbage in, garbage out c. GIGahertz Output d. GIGabyte Operation

garbage in, garbage out

The ____ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value. a. pop( ) b. key( ) c. value( ) d. get( )

get( )

The ___ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value

get()

What is another name for the accessor methods?

getters

When possible, you should avoid using _______ variables in a program. a. local b. global c. reference d. parameter

global

A variable that is visible to every function in a program file is a _______. a. local variable b. universal variable c. program-wide variable d. global variable

global variable

If the start index is ________ the end index, the slicing expression will return an empty string.

greater than

If the start index is ________ the end index, the slicing expression will return an empty string. equal to less than greater than less than or equal to

greater than

if the star index is _______ the end index.....

greater than

The physical devices that a computer is made of are referred to as __________. a. hardware b. software c. the operating system d. tools

hardware

Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not? a. temperature b. feverTest c. hasFever d. fever

hasFever

The first line of a function definition is known as the _______. a. body b. introduction c. initialization d. header

header

A _______ is a diagram that g1ves a visual representation of the relationships between functions in a program. a. flowchart b. function relationship chart c. symbol chart d. hierarchy chart

hierarchy chart (also called a 'structure chart').

You use a(n) _____ statement to write a single alternative decision structure. a. test-jump b. if c. if-else d. if-call

if

You use a(n) _____ statement to write a dual alternative decision structure. a. test-jump b. if c. if-else d. if-call

if-else

What statement do you use in Python to write a dual alternative decision structure?

if..... else

Tuples are _______________ , which means that once a tuple is created, it cannot be changed.

immutable

means that once they are created, they cannot be changed

immutable

strings are immutable/mutable

immutable

What import statement do you need to write in a program that uses the math module?

import math; In order to call a function that is stored in a module, you have to write an import statement at the top of your program. An import statement tells the interpreter the name of the module that contains the function.

In order to create a graph in Python, you need to include which? import matplotlib import pyplot import matplotlib.pyplot import pyplot import matplotlib

import matplotlib.pyplot

in order to create a graph in python, you need to include?

import.matplotlib.pyplot

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the _____ operator. included of in not in

in

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the ________ operator.

in

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the ________ operator. in included isin isnotin

in

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the __________ operator.

in

In order to avoid KeyError exceptions, you can check whether the key is in the dictionary using the _ operator

in

The _______________ operator can be used to determine whether one string is contained in another string.

in

This operator determines whether one string is contained inside another string

in

This operator determines whether one string is contained inside another string. a. contains b. is in c. == d. in

in

You can use the ___ operator to determine whether a key exists in a dictionary

in

You can use the ____ operator to determine whether a key exists in a dictionary. a. & b. in c. ^ d. ?

in

in

in order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the _____ operator

This is a number that identifies an item in a list. a. element b. index c. bookmark d. identifier

index

Which of the following is the correct way to open a file named users.txt in 'r' mode?

infile = open('users.txt', 'r')

A(n) _______ loop has no way of ending and repeats until the program is interrupted. a. indeterminate b. interminable c. infinite d. timeless

infinite

The _______ method is automatically called when an object is created. a. init b. _ _init_ _ c. _ _str_ _ d. _ _object_ _

init

Mice, trackpads, keyboards, scanners, joysticks are all examples of ________ devices.

input

The integrity of a program's output is only as good as the integrity of the program's a. compiler . .b. programming language. c. input. d. debugger.

input

A file that data is read from is known as a(n) a. input file. b. output file. c. sequential access file. d. binary file.

input file

This built-in function can be used to read input that has been typed on the keyboard. a. input() b. get_input() c. read_ input ( ) d. keyboard ( )

input()

What method can be used to place an item in the list at a specific index?

insert

What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add

insert

Which method can be used to place an item at a specific index in a list?

insert

An object is a(n) _______. a. blueprint b. cookie cutter c. variable d. instance

instance

What attributes belong to a specific instance of the class?

instance

Tuple

is a sequence, very much like a list, but is an immutable sequence, which means that that once a tuple is created, its contents cannot be changed.

slice

is a span of items that are taken from a sequence. A slicing expression selects a range of elements from a sequence.

Application software a. processes applications for jobs, school admission, etc. b. is any software that runs with the support of the operating system. c. was invented by Microsoft. d. is applied to the computer for the purpose of running the operating system. e. none of the above.

is any software that runs with the support of the operating system.

A binary digit a. is either positive or negative. b. is zero or one. c. requires one byte of storage. d. is 2. e. is none of the above.

is zero or one

Returns true if the string contains only alphabetic letters or digits and is at least one character in length. Returns false otherwise.

isalnum( )

Returns true if the string contains only alphabetic letters and is at least one character in length. Returns false otherwise.

isalpha( )

Returns true if the string contains only numeric digits and is at least one character in length. Returns false otherwise.

isdigit( )

Which method can you use to determine whether an object is an instance of a class?

isintnace

Returns true if all of the alphabetic letters in the string are lowercase, and the string contains at least one alphabetic letter. Returns false otherwise.

islower( )

Returns true if the string contains only whitespace characters and is at least one character in length. Returns false otherwise. (Whitespace characters are spaces, newlines (\n), and tabs (\t).

isspace( )

Which of the following string methods can be used to determine if a string contains only '\n' characters?

isspace()

Returns true if all of the alphabetic letters in the string are uppercase, and the string contains at least one alphabetic letter. Returns false otherwise.

isupper( )

What does it mean when the readline method returns an empty string?

it has attempted to read beyond the end of a file.

What is a file's read position? Initially, where is the read position when an input file is opened?

it marks the location of the next item that will be read from the file. When a file is opened for reading, a special value known as a read position is internally maintained for that file. Initially, the read position is set to the beginning of the file.

How does a value-returning function differ from the void functions?

it returns a value back to the part of the program that called it.

What is the purpose of the return statement in a function?

it returns control back to the main function.

Which method would you use to get all the elements in a dictionary returned as a list of tuples?

items

Which method would you use to get all the elements in a dictionary returned as a list of tuples? pop items list keys

items

Which method would you use to returns all the elements in the dictionary as a list of tuples? a. list b. items c. pop d. keys

items

The ____ method returns all of a dictionary's keys and their associated values as a sequence of tuples. a. keys_values( ) b. values( ) c. items ( ) d. get( )

items ( )

The ___ method returns all of a dictionary's kesy and their associated values as a sequence of tuples

items()

Which method would you use to get all the elements in a dictionary returned as a list of tuples? A. list() B. keys() C. items() D. pop()

items()

Each repetition of a loop is known as a(n) _______. a. cycle b. revolution c. orbit d. iteration

iteration

In a dictionary, you use a(n) _ to locate a specific value.

key

In a dictionary, you use a(n) _____ to locate a specific value. a. datum b. index c. item d. key

key

In a dictionary, you use a(n) ________ to locate a specific value.

key

In a dictionary, you use a(n) ________ to locate a specific value. element item datum key

key

In a dictionary, you use a(n) ________ to locate a specific value. a. item b. element c. datum d. key

key

In a dictionary, you use a(n) __________ to locate a specific value.

key

The words that make up a high-level programming language are called __________ a. binary instructions b. mnemonics c. commands d. key words

key words

The ________ method returns all of a dictionary's keys as a dictionary view.

keys or keys() Note: I had put items before but the answer was wrong. Make sure it's keys

Words that have a special meaning in a programming language are called ________.

keywords

The built-in function _______________ returns the length of a sequence.

len

This function returns the length of a list. a. length b. size c. len d. lengthof

len

This function returns the length of a string. a. length b. size c. len d. lengthof

len

Which function would you use to get the number of elements in a dictionary? size length len invalid code

len

Which would you use to get the number of elements in a dictionary?

len

Which would you use to get the number of elements in a dictionary? sizeof size length len

len

The ____ function returns the number of elements in a dictionary: a. size( ) b. len( ) c. elements( ) d. count( )

len( )

The following function returns the number of elements in a set: a. size( ) b. len( ) c. elements( ) d. count( )

len( )

The ___ function returns the number of elements in a dictionary

len()

the following functoin returns the number of elements in a set

len()

This is a prewritten function that is built into a programming language. a. standard function b. library function c. custom function d. cafeteria function

library function

What method can be used to convert a tuple to a list?

list

What method can be used to convert a tuple to a list? append tuple insert list

list

Which method can be used to convert a tuple to a list?

list

Built-in function to convert a tuple to a list

list ( )

A _______ is a variable that is created inside a function. a. global variable b. local variable c. hidden variable d. none of the above; you cannot create a variable inside a function

local variable

A _______ error does not prevent the program from running, but causes it to produce incorrect results. a. syntax b. hardware c. logic d. fatal

logic

The purpose of testing a program with different combinations of data is to expose run-time and _______ errors.

logical

and, or, and not are _____ operators. a. relational b. logical c. conditional d. ternary

logical

Returns a copy of the string with all alphabetic letters converted to lowercase. Any character that is already lowercase, or is not an alphabetic letter, is unchanged.

lower( )

The _______________ method returns a copy of the string with all alphabetic letters converted to lower case.

lower()

This string method returns a copy of the string with all leading whitespace characters removed. a. lstrip b. rstrip c. remove d. strip_leading

lstrip

Returns a copy of the string with all leading whitespace characters removed. Leading whitespace characters are spaces, newlines (\n), and tabs (\t) that appear at the beginning of the string.

lstrip( )

The char argument is a string containing a character. Returns a copy of the string with all instances of char that appear at the beginning of the string removed.

lstrip(char)

Computers can only execute programs that are written in __________ a. Java b. assembly language c. machine language d. Python

machine language

The computer stores a program while the program is running, as well as the data that the program is working with, in __________ a. secondary storage b. the CPU c. main memory d. the microprocessor

main memory

This built-in function returns the highest value in a list. a. highest b. max c. greatest d. best of

max

Mutable

means their elements can be changed

The procedures that an object performs are called a. methods b. actions c. modules d. instances

methods

What are the procedures that an object performs called?

methods

Today, CPUs are small chips known as __________ a. ENIACs b. microprocessors c. memory chips d. operating systems

microprocessors

Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not? a. divisible b. isPrime c. mightBePrime d. number

mightBePrime

The _______________ function returns the item that has the lowest value in the sequence.

min

What are the short words that are used in assembly language called?

mnemonics

A(n) _______ method stores a value in a data attribute or changes its value in some other way. a. modifier b. constructor c. mutator d. accessor

mutator

Assume the following statement appears in a program: mylist = [ ] Which of the following statements would you use to add the string 'Labrador' to the list at index 0? a. mylist[0] = 'Labrador' b. mylist.insert(0, 'Labrador') c. mylist. append ( 'Labrador' ) d. mylist.insert('Labrador', 0)

mylist.insert(0, 'Labrador')

Assume the variable, name contains ELMO. Write the necessary codes to display the content of the variable, name in a vertical form: E L M O

name='ELMO' for i in name: print(i)

When working with multiple sets of data, one would typically use a ________.

nested list

When working with multiple sets of data, one would typically use a(n)

nested list

When working with multiple sets of data, one would typically use a(n) _____.

nested list

The _____ operator takes a Boolean expression as its operand and reverses its logical value. a. and b. or c. not d. either

not

What happens when a piece of data is written to a file?

not sure!!!!!!!!!!!!!!!!!!!!!!!!

In one approach to identifying the classes in a problem, the programmer identifies the _______ in a description of the problem domain. a. verbs b. adjectives c. adverbs d. nouns

nouns

What is, conceptually, a self-contained unit that consists of data attributes and methods that operate on the data attributes?

object

The programming practice is centered on creating objects. a. object-centric b. objective c. procedural d. object-oriented

object-oriented

What type of programming contains class definitions?

object-oriented

When a program is not running, it is stored a. on a disk. b. in level-2 cache (L2). c. in main memory. d. on the ethernet or wifi.

on a disk

The primary Difference between a tuple and a list is taht

once a tuple is created, it cannot be changed

The primary difference between a tuple and list is that _____ when creating a tuple you don't use commas to separate elements a tuple can only include string elements a tuple cannot include lists as elements once a tuple is created, it cannot be changed

once a tuple is created, it cannot be changed

The primary difference between a tuple and list is that _____.

once a tuple is created, it cannot be changed

The primary difference between a tuple and list is that ________.

once a tuple is created, it cannot be changed

Which step creates a connection between a file and a program?

open the file

Which step creates a connection between a file and a program? a. Open the file. b. Read the file. c. Process the file. d. Close the file.

open the file

Before a file can be used by a program, it must be a. formatted. b. encrypted. c. closed. d. opened.

opened

In the expression 12 + 7, the values on the right and left of the + symbol are called a. operands b. operators c. arguments d. math expressions

operands

In an event-driven program, the ________ accepts the user's commands. a. register b. CPU c. operating system d. GUI

operating system

A compound Boolean expression created with the ____ operator is true if either of its subexpressions is true. a. and b. or c. not d. either

or

Which of the following is the correct way to open a file named users.txt to write it?

outfile = open('users.txt', 'w')

Which of the following is the correct way to open a file named users.txt to write to it?

outfile = open('users.txt', 'w')

A video display is a(n) ________ device. a. output b. input c. secondary storage d. main memory

output

Monitors, printers, status lights are all examples of _______ devices.

output

A file that data is written to is known as a(n) a. input file. b. output file. c. sequential access file. d. binary file.

output file

A(n) _______ is a special variable that receives a piece of data when a function is called. a. argument b. parameter c. header d. packet

parameter

What are the variables that receive pieces of data in a function called?

parameters

What function do you call to pickle an object?

pickle.dump

What function do you call to retrieve and unpickle an object?

pickle.load

In Python, object serialization is called ______

pickling

What is the process used to convert an object to a stream of bytes that can be saved in a file? Pickling Streaming Writing Dumping

pickling

The tiny dots of color that digital images are composed of are called __________ a. bits b. bytes c. color packets d. pixels

pixels

Which method would you use to get the value associated with a specific key and remove that key - value pair from the dictionary?

pop

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

pop

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary? items pop popitem list

pop

The ____ method returns the value associated with a specified key and removes that key-value pair from the dictionary . a. pop( ) b. random( ) c. popitem( ) d. rand_pop( )

pop( )

the ___ method returns the value associated with a specified key, and removes that key value pair from the dictionary

pop()

The ____ method returns a randomly selected key-value pair from a dictionary. a. pop( ) b. random( ) c. popitem( ) d. rand pop( )

popitem( )

the ___ method returns a randomly selected key-value pair from a dictionary

popitem()

The while loop is a _______ type of loop. a. pretest b. no-test c. prequalified d. post-iterative

pretest

The input operation that appears just before a validation loop is known as the a. prevalidation read. b. primordial read. c. initialization read. d. priming read.

priming read

A(n) ________ is a set of real-world objects, parties, and major events related to the problem.

problem domain

The programming practice is centered on creating functions that are separate from the data that they work on. a. modular b. procedural c. functional d. object-oriented

procedural

A(n) is a set of instructions that a computer follows to perform a task. a. compiler b. program c. interpreter d. programming language

program

An informal language that has no syntax rules and is not meant to be compiled or executed is called _______. a. faux code b. pseudocode c. Python d. a flowchart

pseudocode

When an exception is generated, it is said to have been _______ a. built b. raised c. caught d. killed

raised

This standard library function returns a random integer within a specified range of values. a. random b. randint c. random_integer d. uniform

randint

A __________ access file is also known as a direct access file

random

A(n) __________ access file is also known as a direct access file.

random

This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0). a. random b. randint c. random_integer d. uniform

random

What type of file access jumps directly to any piece of data in a file without reading the data that came before it?

random

What type of file access jumps directly to any piece of data in a file without reading the data that that came before it?

random

Suppose you want to select a random number from the following sequence: 0, 5, 10, 15, 20, 25, 30 What library function would you use?

randrange ex: num = random.randrange(0, 5, 10, 15, 20, 25, 30)

When a file has been opened using the 'r' mode specifier ,which method will return the file's contents as a string?

read

When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string?

read

Which method will return an empty string when it has attempted to read beyond the end of a file?

read

This marks the location of the next item that will be read from a file. a. input position b. delimiter c. pointer d. read position

read position

What do you call the process of retrieving data from a file?

reading data

What is the process of retrieving data from a file called?

reading data

the process of retrieving data is called from a file is

reading data

This file object method returns a list containing the file's contents. a. to_list b. getlist c. readline d. readlines

readlines

The symbols >, <, and == are all _____ operators. a. relational b. logical c. conditional d. ternary

relational

This method removes an element and raises an exception if the element is not found.

remove

This set method removes an element and raises an exception if the element is not found. a. remove b. discard c. delete d. erase

remove

del Statement

removes an element from a specific index, regardless of the item that is stored at that index.

The old and new arguments are both strings. The method returns a copy of the string with all instances of old replaced by new.

replace(old, new)

In one approach to identifying a class's data attributes and methods, the programmer identifies the class's ______. a. responsibilities b. name c. synonyms d. nouns

responsibilities

This statement causes a function to end and sends a value back to the part of the program that called the function. a. end b. send c. exit d. return

return

What statement do you have to have in a value-returning function?

return expression, where expression holds the value that is to be returned to the calling function. This can be any value, variable or expression that has a value.

MM lstrip()

returns a copy of the string all leading whitespace characters removed; leading whitespace characters appear at beginning of string

MM lower()

returns a copy of the string with all alphabetic letters converted to lowercase; any character that is already lowercase is left unchanged

MM upper()

returns a copy of the string with all alphabetic letters converted to uppercase; any character that is already uppercase is left unchanged

MM strip(char)

returns a copy of the string with all instances of "char" that appear at the beginning and end of the string removed

MM rstrip(char)

returns a copy of the string with all instances of "char" that appear at the end of the string removed

MM strip()

returns a copy of the string with all leading and trailing whitespace characters removed

MM rstrip()

returns a copy of the string with all trailing whitespace characters removed

strings in Python have a method named "split" which:

returns a list containing the words in the string; uses spaces as separators

STM islower()

returns true if all of the alphabetic letters in a string are lowercase and the string contains at least one alphabetic letter

STM isupper()

returns true if all of the alphabetic letters in the string are uppercase and the string contains at leas one alphabetic letter

STM isalpha()

returns true if string contains only alphabetic letters and is at least one character in length

STM isalnum()

returns true if string contains only alphabetic letters or digits and is at least one character in length

STM isspace()

returns true if string contains only whitespace characters and is at least one character in length

STM isdigit()

returns true only if string contains numeric digits and is at least one character in length

Which method could be used to strip specific characters from the end of a string

rstrip

Which method could be used to strip specific characters from the end of a string?

rstrip

Returns a copy of the string with all trailing whitespace characters removed. Trailing whitespace characters are spaces, newlines (\n), and tabs (\t) that appear at the end of the string.

rstrip( )

The char argument is a string containing a character. The method returns a copy of the string with all instances of char that appear at the end of the string removed.

rstrip(char)

A(n) _______ is the part of a program in which a variable may be accessed. a. declaration space b. area of visibility c. scope d. mode

scope

Which section in the UML holds the list of the class's data attributes?

second

Which section in the UML holds the list of the class's data attributes? a. first section b. second section c. third section d. fourth section

second section

Flash drives, CDs, external disks are all examples of ________ storage (memory) devices.

secondary

A type of memory that can hold data for long periods of time, even when there is no power to the computer, is called __________ a. RAM b. main memory c. secondary storage d. CPU storage

secondary storage

When a method is called, what does Python make to reference the specific object on which the method is supposed to operate?

self parameter

A(n) _______ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. a. sentinel b. flag c. signal d. accumulator

sentinel

When working with this type of file, you access its data from the beginning of the file to the end of the file. a. ordered access b. binary access c. direct access d. sequential access

sequential access

What are the two types of file access?

sequential access and direct access

A ______ contains a collection of unique values and works like a mathematical set.

set

A(n) _______________ is an object that holds multiple unique items of data in an unordered manner.

set

Actions taken by the computer when a function is called, such as allocating memory for parameters and local variables, are referred to as ______. a. overhead b. set up c. clean up d. synchronization

set up

What is another name for the mutator methods?

setters

The process of calling a function requires a. a quick memory access b. one action to be performed by the computer c. several actions to be performed by the computer d. a slow memory access

several actions to be performed by the computer

A _____ structure provides one alternative path of execution. a. sequence b. single alternative decision c. one path alternative d. single execution decision

single alternative decision

A _______ is a single function that the program must perform in order to satisfy the customer. a. task b. software requirement c. prerequisite d. predicate

software requirement

The code that a programmer writes is called ________ code.

source

This is math module function. a. derivative b. factor c. sqrt d. differentiate

sqrt

The substring argument is a string. The method returns true if the string starts with substring.

startswith(substring)

The third number in string slicing brackets or in the range() function represents the _______________ value.

step or increment

Which method could be used to convert a numeric value to a string?

str

A _______ is a sequence of characters. a. char sequence b. character collection c. string d. text block

string

This string method returns a copy of the string with all leading and trailing whitespace characters removed. a. clean b. strip c. remove_whitespace d. rstrip

strip

Returns a copy of the string with all leading and trailing whitespace characters removed.

strip( )

this string method returns a copy of the string with all the leading and trailing whitespace character removed

strip()

Returns a copy of the string with all instances of char that appear at the beginning and the end of the string removed.

strip(char)

a slice from a string, you get a span of characters from within the string. String slices are also called

substrings

slices of strings

substrings

The rules that govern the correct order and usage of the elements of a language are called the _______ of the language

syntax

The rules that must be followed when writing a program are called __________ a. syntax b. punctuation c. key words d. operators

syntax

In general, what are the two types of files? What is the difference between these two types of files?

text and binary A text file contains data that has been encoded as text, using a scheme such as ASCII or Unicode. The file may be opened and viewed in a text editor such as Notepad. A binary file contains data that has not been converted to text. The data that is stored in a binary file is intended only for a program to read. You cannot view the contents of a binary file with a text editor.

The contents of this type of file can be viewed in an editor such as Notepad. a. text file b. binary file c. English file d. human-readable file

text file

replace(old,new)

the "old" and "new" arguments are both strings; the method returns a copy of the string with all instances of "old" replaced by "new"

startswith(substring)

the "substring" argument is a string; the method returns true if the string starts with "substring"

The part of a computer that runs programs is called a. RAM b. secondary storage c. mam memory d. the CPU

the CPU

Which of the following is associates with a specific file and provides a way for the program to work with that file?

the FILE OBJECT

A set of standard diagrams for graphically depicting object-oriented systems is provided by _____. a. the Unified Modeling Language b. flowcharts c. pseudocode d. the Object Hierarchy System

the Unified Modeling Language

This removes an item at a specific index in a list. a. the remove method b. the delete method c. the del statement d. the kill method

the del statement

You use ____ to delete an element from a dictionary. a. the remove method b. the erase method c. the delete method d. the del statement

the del statement

Which of the following is associated with a specific file and provides a way for the program to work with that file?

the file object

This string method returns true if a string contains only alphabetic characters and is at least one character in length. a. the isalpha method b. the alpha method c. the alphabetic method d. the isletters method

the isalpha method

This string method returns true if a string contains only alphabetic characters and is at least one character in length

the isalpha() method

This string method returns true if a string contains only numeric digits and is at least one character in length. a. the digit method b. the isdigit method c. the numeric method d. the isnumber method

the isdigit method

this string method returns true if a string contains only numeric digits and is at least one character in length

the isdigit() method

You can use this to determine whether an object is an instance of a class. a. the in operator b. the is_object_of function c. the isinstance function d. the error messages that are displayed when a program crashes

the isinstance function

What happens if the same seed value is always used for generating random numbers?

the random number functions would always generate the same series of pseudorandom numbers.

What is the difference between calling a list's remove method and using the del statement to remove an element?

the remove method is used to remove a specific element in a list. the del method is used to remove any element that is present at a specific index, regardless of what that element is.

When the _ _init_ _ method executes, what does the self parameter reference?

the selfparameter is automatically set to the object that was just created

if the 'start' index is greater than the 'end' index:

the slicing expression will return an empty string

What is the return value of the string method lstrip()? the string with all leading tabs removed the string with all leading whitespaces removed the string with all whitespaces removed the string with all leading spaces removed

the string with all leading whitespaces removed

When the random module is imported, what does it use as a seed value for random number generation?

the system time from the computer's internal clock

In an event-driven environment, the user interacts with a. the graphical unit b. the user interface c. the register d. the CPU

the user interface

What is a local variable's scope?

the variable can be used only locally, within the function in which it is created. No statement outside the function may access the variable.

Which section in the UML holds the list of the class's methods?

third

Which section in the UML holds the list of the class's methods? a. first section b. second section c. third section d. fourth section

third section

A design technique that programmers use to break down an algorithm into functions is known as _______. a. top-down design b. code simplification c. code refactoring d. hierarchical subtasking

top-down design

A compiler a. maintains a collection of programs b. tests a program's logic c. translates source code into executable code d. translates executable code to machine code

translates source code into executable code

: Different functions can have local variables with the same names

true

In Python, one can have a list of variables on the left side of the assignment operator

true

Lists are dynamic data structures such that items may be added to them or removed from them.

true

One of the reasons not to use global variables is that it makes a program hard to debug.

true

Python allows for passing multiple arguments to a function.

true

Python function names follow the same rules for naming variables.

true

The following statement creates an empty dictionary mydct = { }

true

The function header marks the beginning of the function definition?

true

The index - 1 identifies the last element in a list.

true

True/False: A value-returning function is like a simple function except that when it finishes it returns a value back to the called part of the program.

true

True/False: The lstrip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.

true

sets store their elements in an unordered fashion

true

the following statement creates an empty set: myset = ()

true

the remove method raises an exception if the specified element is not found in the set

true

You write this statement to respond to exceptions. a. run/ handle b. try/except c. try /handle d. attempt/except

try/except

What statement can be used to handle some of the run-time errors in a program? a. exception statement b. try statement c. try/except statement d. exception handler statement

try/except statement

What method can be used to convert a list to a tuple?

tuple

What method can be used to convert a list to a tuple? append tuple insert list

tuple

which method can be used to convert a list to a tuple?

tuple

Each element in a dictionary view is a ________.

tuple Note: My original answer was key-value pair, but was incorrect. It was tuple

Built-in function to convert a list to a tuple

tuple ( )

Negative numbers are encoded using the __________ technique. a. two's complement b. floating point c. ASCII d. Unicode

two's complement

This standard library function returns a random floating-point number within a specified range of values. a. random b. randint c. random_integer d. uniform

uniform

The ________ of two sets is a set that contains all the elements of both sets.

union

What method can be used to add a group of elements to a set? add addgroup update Elements must be added one at a time.

update

Which method can be used to add a group of elements to a set?

update

You can add a group of elements to a set with this method

update

You can add a group of elements to a set with this method. a. append b. add c. update d. merge

update

Returns a copy of the string with all alphabetic letters converted to uppercase. Any character that is already uppercase, or is not an alphabetic letter, is unchanged.

upper( )

A _____ is any hypothetical person using a program and providing input for it. a. designer b. user c. gumea p1g d. test subject

user

The ______ is the part of a computer with which the user interacts. a. central processing unit b. user interface c. control system d. interactivity system

user interface

Which of the following statements creates a tuple? a. values [1, 2, 3, 4] b. values {1, 2, 3, 4} c. values ( 1) d. values ( 1,)

values ( 1,)

A _____ is a name that references a value in the computer's memory. a. variable b. register c. RAM slot d. byte

variable

A location in memory used for storing data and given a name in a computer program is called a _________ because the data in the location can be changed.

variable

Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist?

w

IndexError

will occur if you try to use an index that is out of range for a particular string

Which of the following will create an object, WOKER_JOEY, of the WORKER class?

worker_joes = Worker()

What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print(mystr)

yesnono

What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print(mystr) yes + no yes + no yesnono yesnoyesno yes + no * 2

yesnono

mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print (mystr)

yesnono

After the following statement executes, what elements will be stored in the myset set? myset = set('a bb ccc dddd')

{ ' ', 'a', 'b', 'c', 'd'}

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)?

{ 1 : 'January', 2 : 'February', ... 12 : 'December' }

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)? { 1, 2,... 12 : 'January', 'February',... 'December' } { 1 ; 'January', 2 ; 'February', ... 12 ; 'December'} { 1 : 'January', 2 : 'February', ... 12 : 'December' } [ '1' : 'January', '2' : 'February', ... '12' : 'December' ]

{ 1 : 'January', 2 : 'February', ... 12 : 'December' }

You can use ____ to create an empty dictionary. a. { } b. ( ) c. [ ] d. empty( )

{ }

cities = {'GA' , ....

{'CA' : 'San Diego' , 'NY' : 'Albany' , 'GA' ,: 'Atlanta'}

1. What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities)

{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities)

{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities) {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'} {'CA': 'Sacramento'} {'NY': 'Albany', 'GA': 'Atlanta'} ['CA': 'Sacramento']

{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities) A. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} B. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'} C. {'FL': 'Tallahassee'} D. KeyError

{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'Ga':'Atl','NY':'Alb','CA':'San D'} if 'FL' in cities: del cities['FL'] cities['FL']='Tallah' print(cities)

{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)

{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities) {'FL': 'Tallahassee'} {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} KeyError {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'}

{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities)

{'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'}

What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities) KeyError {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'} {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} {'FL': 'Tallahassee'}

{'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'}

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = '5556666' {'John' : '5556666', 'Julie' : '5557777'} {'John' : '5556666'} {'John' : '5555555', 'Julie' : '5557777'} This code is invalid.

{'John' : '5556666', 'Julie' : '5557777'}

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = 5556666'

{'John' : '5556666', 'Julie' : '5557777'}

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = 5556666' a. {'John' : '5556666'} b. {'John' : '5556666', 'Julie' : '5557777'} c. This code is invalid. d. {'John' : '5555555', 'Julie' : '5557777'}

{'John' : '5556666', 'Julie' : '5557777'}

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = '5556666'

{'John' : '5556666', 'Julie' : '5557777'}

What is the value of the variable phones after the execution of the following code? phones = {'John': '5555555', 'Julie' : '7777777'} phones['John'] = '1234567' {'John': '5555555', 'Julie' : '7777777'} {'John': '1234567', 'Julie' : '7777777'} {'John': '1234567' } invalid code

{'John': '1234567', 'Julie' : '7777777'}

set1 = set ( [1,2,3] ) set2 = set( [2,.3,4] ) set3 = set1.symmetric_difference (set2)

{1, 4}

you can use __ to create an empty dictionary

{}

this operator can be used to find the union of two sets

|


Ensembles d'études connexes

psychopharmacology exam 3 quizzes

View Set

ER Practice Q's - Week 2 - Male Reproductive System

View Set

Perry Real Estate College - National Practice Tests 1-5

View Set

Evidence of Chemical Reactions assignment and quiz

View Set

MKT 300 UKY Holly Hapke exam 2 practice questions

View Set

U2 S2 Eukaryotic and Prokaryotic homework

View Set

Business Law Exam #1 Chapter 1 - 5

View Set

California Real Estate Principles Vocabulary

View Set

Physics Unit 4 - work, power and energy

View Set