Python final study
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 symbol marks the beginning of a comment in Python. a. & b. * c. ** d. #
#
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
This is an operator that raises a number to a power. a. % b.* c. ** d. /
**
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 problem domain?
A written description of the real-world objects, parties, and major events related to the problem
This type of function returns either True or False. a. Binary b. true false c. Boolean d. logical
Boolean
What type of exception does a program raise when it tries to open a nonexistent file?
IOError
A list from which the user may select an item
Listbox
If the input that is read by the priming read is valid, how many times will the input validation loop iterate?
None
When a program runs on a computer, it is stored in _______.
RAM
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.
Tuples in Python are immutable. T or F
True
How do you find the length of a string?
Use the len( ) function
How do you determine the number of elements in a set?
You pass the set as an argument to the len function.
How do you retrieve data from an Entry widget?
You use an Entry widget's get method to retrieve the data that the user has typed into the widget.
A(n) _______ is a piece of data that is sent into a function. a. argument b. parameter c. header d. packet
argument
Briefly describe the following tkinter widget: d) Frame
d) Frame- A container that can hold other widgets
This is a single piece of data within a record. a. field b. variable c. delimiter d. subrecord
field
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.
This string method returns the lowest index in the string where a specified substring is found. a. first index of b. locate c. find d. index of
find
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)
You use the Entry widget's ______ ______ to retrieve the data that has been typed into the widget.
get method
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( )
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
A ______ ______ ______ allows the user to interact with the operating system and other programs using graphical elements such as icons, buttons, and dialog boxes.
graphical user interface
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').
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()
An object is a(n) _______. a. blueprint b. cookie cutter c. variable d. instance
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( )
We can prevent an AttributeError exception from occurring by using the built-in function ______. You can use the ________ function to determine whether an object is an instance of a specific class, or a subclass of that class.
isinstance
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( )
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.
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 ( )
Each repetition of a loop is known as a(n) _______. a. cycle b. revolution c. orbit d. iteration
iteration
The part of a problem that is solved with recursion is the _______ case. a. base b. iterative c. unknown d. recursion
iterative
Mutable
means their elements can be changed
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
You write this statement to respond to exceptions. a. run/ handle b. try/except c. try /handle d. attempt/except
try/except
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
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
An item that appears in a program's graphical user interface is known as a(n) ______ a. gadget b. widget c. tool d. iconified object
widget
You can use ____ to create an empty dictionary. a. { } b. ( ) c. [ ] d. empty( )
{ }
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. ^
&
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'
When you open a file for the purpose of saving a pickled object to it, what file access mode do you use?
'wb'
This operator can be used to find the difference of two sets. a. I b. & c. - d. ^
-
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 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?
Which of the following statements will cause an error? a. x = 17 b. 17 = X C. X = 99999 d. X = '17'
17 = X
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.
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 base case?
A case in which the problem can be solved without recursion
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 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.
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
What is an event-driven program?
A program that responds to events that take place, such as the user clicking a button
It is said that a recursive algorithm has more overhead than an iterative algorithm. What does this mean?
A recursive algorithm requires multiple method calls. Each method call requires several actions to be performed
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.
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 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.
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
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.
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 list. a. A ValueError exception will occur. b. An IndexError exception will occur. c. The list will be erased and the program will continue to run. d. Nothing-the invalid index will be ignored.
An IndexError exception will occur.
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
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.
What can you accomplish by associating a StringVar object with a Label widget?
Any value that is stored in the StringVar object will automatically be displayed in the Label widget.
How can you use an IntVar object to determine whether a Checkbutton has been selected?
As with Radiobuttons, you can use an IntVar object along with a Checkbutton widget. Unlike Radiobuttons, however, you associate a different IntVar object with each Checkbutton. You set the intVar objects to initialize at 0. When a Checkbutton is selected, its associated IntVar object will hold the value 1. When a Checkbutton is not selected, its associated Intvar object will hold the value 0.
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.
Look at the fo llowing code, which is the first line of a class definition. What is the name of the superclass? What is the name of the subclass? class Canary(Bird}:
Bird is the superclass Canary is the subclass.
A(n) _____ expression has a value of either true or false. a. binary b. decision c. unconditional d. Boolean
Boolean
What is a Boolean expression?
Boolean expressions check the truth of an expression, it checks whether the expression is true or false.
A button that can cause an action to occur when it is clicked.
Button
You use the ______ ______ to create a standard button in a window. When the user clicks a button, a specified function or method is called.
Button widget
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.
A rectangular area that can be used to display graphics.
Canvas
What is a recursive case?
Cases in which the problem is solved using recursion
______ buttons, which may appear alone or in groups, allow the user to make yes/no or on/off selections.
Check
A button that may be in either the "on" or "off" position.
Checkbutton
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.
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.
How can you use a StringVar object to update the contents of a Label widget?
Create a label and associate it with the StringVar object. Any value stored in the StringVar object will automatically be displayed in the label.
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 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 is a loop iteration?
Each execution of the body of a loop is known as an iteration
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
This widget is an area in which the user may type a single line of input from the keyboard. a. Label b. Entry c. TextLine d. Input
Entry
An ______ ______ is a rectangular area that the user can type input into.
Entry widget
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 list can be a dictionary key. T or F
False
A mutually exclusive relationship is automatically created among all Checkbutton widgets in the same container. T or F
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
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 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 you cannot write functions that accept multiple arguments. T or F
False
In the base case, a recursive method calls itself with a smaller version of the original problem. T or F
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 have a base case in all recursive algorithms. T or F
False
It is not necessary to initialize accumulator variables. T or F
False
It is not possible to call a superclass's __ init __ method from a subclass's __ init __ method. T or F
False
Lists in Python are immutable. T or F
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
Some problems can be solved through recursion only. T or F
False
The Python language has built-in keywords for creating GUI programs. T or F
False
The data that that you retrieve from an Entry widget is always of the int data type. T or F
False
The dictionary method popitem does not raise an exception if it is called on an empty dictionary. T or F
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 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 isupper method converts a string to all uppercase characters. T or F
False
The keys in a dictionary must be mutable objects. T or F
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
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
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 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 do not need to have an import statement in a program to use the functions in the random module. T or F
False
Look at the following class definition. What is the name of the superclass? What is the name of the subclass? class Tiger(Felis):
Felis is the superclass Tiger is the subclass
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.
A ______ is a container that can hold other widgets.
Frame
A container that can hold other widgets.
Frame
This widget is a container that can hold other widgets. a. Grouper b. Composer c. Fence d. Frame
Frame
You can use ______ to organize the widgets in a window.
Frames
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.
These types of programs are event driven. a. command line b. text-based c. GUI d. procedural
GUI
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
Which of these is not a programming language? a. C b. C++ c. HTML d. Java
HTML
This operator can be used to find the union of two sets. a. I b. & c. - d. ^
I
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.
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.
What is direct recursion?
In direct recursion, a recursive method calls itself
What is indirect recursion?
In indirect recursion, method A calls method B, which in turn calls method A.
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.
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.
______ allows a new class to extend an existing class. The new class inherits the members of the class it extends.
Inheritance
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.
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 does a subclass inherit from its superclass?
It inherits all the superclass's attributes.
When you retrieve a value from an Entry widget, of what data type is it?
It is a string.
What is pseudocode?
It is an informal description of the algorithm.
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.
Suppose a program uses two classes: Airplane and JumboJet. Which of these would most likely be the subclass? a. Airplane b. JumboJet c. Both d. Neither
JumboJet
An element in a dictionary has two parts. What are they called?
Key and value
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.
An area that displays one line of text or an image.
Label
This widget is an area that displays one line of text. a. Label b. Entry c. TextLine d. Canvas
Label
When a StringVar object is associated with a ______ ______, the ______ ______ displays any data that is stored in the StringVar object.
Label widget
You use the ______ ______ to display text in a window.
Label widget
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.
A list of menu choices that are displayed when the user clicks a Menubutton widget.
Menu
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.
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.
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
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.
If you create two Label widgets and call their pack methods with no arguments, how will the Label widgets be arranged inside their parent widget?
One will be stacked on top of the other.
If you create two widgets and call their pack methods with no arguments, how will the widgets be arranged inside their parent widget?
One will be stacked on top of the other.
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
_______ allows subclasses to have methods with the same names as methods in their superclasses. It gives the ability for a program to call the correct method depending on the type of object that is used to call it.
Polymorphism
What are private methods?
Private methods cannot be accessed by entities outside the object. They are designed to be accessed internally.
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 are public methods?
Public methods can be accessed by entities outside the object.
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)
______ buttons normally appear in groups of two or more and allow the user to select one of several possible options.
Radio
A widget that can be either selected or deselected. ______ widgets usually appear in groups and allow the user to select one of several options.
Radiobutton
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
Computer programs typically perform what three steps?
Receiving of input Processing of input Producing output from received input
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.
reverse() Method
Reverses the order of the items in the list.
A widget that allows the user to select a value by moving a slider along a track.
Scale
Can be used with some other types of widgets to provide scrolling ability.
Scrollbar
______ 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
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.
sort() Method
Sorts the items in the list so they appear in ascending order (from the lowest value to the highest value).
An object of this type can be associated with a Label widget, and any data stored in the object will be displayed in the Label. a. StringVar b. LabelVar c. LabelValue d. DisplayVar
StringVar
What type of software controls the internal operations of the computer's hardware?
System Software. Such as Windows, Linux, Mac OS
A widget that allows the user to enter multiple lines of text input.
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.
What is a function definition?
The definition (code) that is written to create a function. It specifies what a function does.
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.
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
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 does a widget's pack method do?
The pack method arranges a widget in its proper position, and it makes the widget visible when the main window is displayed.
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.
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.
You can call this method to close a GUI program. a. The root widget's destroy method b. Any widget's cancel method c. The sys. shutdown function d. The Tk. shutdown method
The root widget's destroy method
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
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.
What does the tkinter module's mainloop function do?
This function runs like an infinite loop until you close the main window.
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.
A container, like a Frame, but displayed in its own window.
Top l evel
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 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 mutually exclusive relationship is automatically created among all Radiobutton widgets in the same container. T or F
True
A subclass can have a method with the same name as a method in the superclass. T or F
True
A tuple can be a dictionary key. T or F
True
An algorithm that uses a loop will usually run faster than an equivalent recursive algorithm. T or F
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
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. T or F
True
Every widget has a quit method that can be called to close the program. T or F
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
In Python the first character of a variable name cannot be a number. T or F
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
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. T or F
True
Polymorphism allows you to write methods in a subclass that have the same name as methods in the superclass. T or F
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
The del statement deletes an item at a specified index in a list. T or F
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 practice of procedural programming is centered on the creation of objects. T or F
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 while loop is a pretest loop. 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 cannot use the isinstance function to determine whether an object is an instance of a subclass of a class. T or F
True
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
Are the elements of a set ordered or unordered?
Unordered
What type of exception does a program raise when it uses the float function to convert a non-numeric string to a number?
ValueError
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.
What is an overridden method?
When a subclass method has the same name as a superclass method, it is often said that the subclass method overrides the superclass method.
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.
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.
What causes a recursive algorithm to stop calling itself?
When it reaches the base case
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.
How can you use an IntVar object to determine which Radiobutton has been selected in a group of Radiobuttons?
When you create a group of Radiobuttons, you associate them all with the same IntVar object. You also assign a unique integer value to each Radiobutton widget. When one of the Radiobutton widgets is selected, it stores its unique integer value in the IntVar object.
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.
How do you create a root widget?
You create an instance of the tkinter module's Tk class.
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.
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.
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. ^
^
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.
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
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.
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
Briefly describe the following tkinter widget: a) Label
a) Label-An area that displays one line of text or an image
A(n) method gets the value of a data attribute but does not change it. a. retriever b. constructor c. mutator d. accessor
accessor
*A(n) _______ variable keeps a running total. a. sentinel b. sum c. total d. accumulator
accumulator
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
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
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
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
Briefly describe the following tkinter widget: b) Entry
b) Entry-An area in which the user may type a single line of input from the keyboard
The part of a problem that can be solved without recursion is the ______ case. a. base b. solvable c. known d. iterative
base
Superclasses are also called ______
base classes
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
Briefly describe the following tkinter widget: c) Button
c) Button- A button that can cause an action to occur when it is clicked
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
A recursive function ______. a. calls a different function b. abnormally halts the program c. calls itself d. can only be called once
calls itself
in Operator
can be used to determine whether an item is contained in a list.
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
A(n) _______ is a component of a class that references data. a. method b. instance c. data attribute d. module
data attribute
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
Subclasses are also called ______
derived classes
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 a function explicitly calls itself it is called _______ recursion. a. explicit b. modal c. direct d. indirect
direct
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
You show inheritance in a UML diagram by _______ from the subclass to the superclass.
drawing a line with an open arrowhead
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
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
The substring argument is a string. The method returns true if the string ends with substring.
endswith(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
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
A function is called once from a program's main function, and then it calls itself four times. The depth of recursion is ______. a. one b. four c. five d. nine
four
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
Inheritance involves a superclass and a subclass. The superclass is the ______ and the subclass is the _______.
general class specialized class
You call this method to retrieve data from an Entry widget. a. get_entry b. data c. get d. retrieve
get
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
means that once they are created, they cannot be changed
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.
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. a. & b. in c. ^ d. ?
in
This is a number that identifies an item in a list. a. element b. index c. bookmark d. identifier
index
When function A calls function B, which calls function A, it is called ______ recursion. a. implicit b. modal c. direct d. indirect
indirect
A(n) _______ loop has no way of ending and repeats until the program is interrupted. a. indeterminate b. interminable c. infinite d. timeless
infinite
In object-oriented programming, ______ is used to create an "is a" relationship among classes.
inheritance
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 words that make up a high-level programming language are called __________ a. binary instructions b. mnemonics c. commands d. key words
key words
Words that have a special meaning in a programming language are called ________.
keywords
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
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( )
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
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
Any problem that can be solved recursively can also be solved with a ______. a. decision structure b. loop c. sequence structure d. case structure
loop
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( )
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
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
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')
The _____ operator takes a Boolean expression as its operand and reverses its logical value. a. and b. or c. not d. either
not
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
The programming practice is centered on creating objects. a. object-centric b. objective c. procedural d. object-oriented
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
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
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
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
This method arranges a widget in its proper position, and it makes the widget visible when the main window is displayed . a. pack b. arrange c. position d. show
pack
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
The tiny dots of color that digital images are composed of are called __________ a. bits b. bytes c. color packets d. pixels
pixels
This characteristic of object-oriented programming allows the correct version of an overridden method to be called when an instance of a subclass is used to call it. a. polymorphism b. inheritance c. generali zation d. specialization
polymorphism
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 a randomly selected key-value pair from a dictionary. a. pop( ) b. random( ) c. popitem( ) d. rand pop( )
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
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
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
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)
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
This file object method returns a list containing the file's contents. a. to_list b. getlist c. readline d. readlines
readlines
a function that calls itself
recursive function
A recursive algorithm must ______ in the recursive case. a. solve the problem without recursion b. reduce the problem to a smaller version of the original problem c. acknowledge that an error has occurred and abort the program d. enlarge the problem to a larger version of the original problem
reduce the problem to a smaller version of the original problem
The symbols >, <, and == are all _____ operators. a. relational b. logical c. conditional d. ternary
relational
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.
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
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
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
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
How do you specify that a widget should be positioned as far left as possible inside its parent widget?
side='left'
What argument would you pass to a widget's pack method to specify that it should be positioned as far left as possible inside the parent widget?
side='left'
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 problem can be solved with recursion if it can be broken down into ______ ______ that are identical in structure to the overall problem.
smaller problems
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
A recursive algorithm must ______ in the base case. a. solve the problem without recursion b. reduce the problem to a smaller version of the original problem c. acknowledge that an error has occurred and abort the program d. enlarge the problem to a larger version of the original problem
solve the problem without recursion
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)
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( )
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)
In an inheritance relationship, the _____ is the specialized class. a. superclass b. master class c. subclass d. parent class
subclass
a slice from a string, you get a span of characters from within the string. String slices are also called
substrings
In an inheritance relationship, the _____ is the general class. a. subclass b. superclass c. slave class d. child class
superclass
In this section we discussed superclasses and subclasses. Which is the general class, and which is the specialized class?
superclass is a general class subclass is a specialized class
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
The part of a computer that runs programs is called a. RAM b. secondary storage c. mam memory d. the CPU
the CPU
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
The number of times that a function calls itself is known as
the depth of recursion
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 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
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
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
When a program runs in a GUI environment, what determines the order in which things happen?
the user determines the order in which things happen because GUI programs must respond to the actions of the user
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.
In Python you can use the ______ module to create simple GUI programs.
tkinter
What module is the StringVar class in?
tkinter
You can use this module in Python to create GUI programs. a. GUI b. PythonGui c. tkinter d. tgui
tkinter
The showinfo function is in this module. a. tkinter b. tkinfo c. sys On d. tkinter.messagebox
tkinter.messagebox
An info dialog box is a simple window that displays a message to the user and has an OK button that dismisses the dialog box. You can use the ______ ______ ______ function to display an info dialog box.
tkinter.messagebox module's showinfo
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