Starting Out with Python 5e (Gaddis) Chapter 1 Introduction to Computers and Programming TRUE/FALSE 1. A software developer is the person with the training to design, create, and test computer programs. ANS: T 2. A computer is a single device that performs different types of tasks for its users. ANS: F 3. All programs are normally stored in ROM and are loaded into RAM as needed for processing. ANS: F 4. The instruction set for a microprocessor is unique and is typically understood only by the microprocessors of the same brand. ANS: T 5. The CPU understands instructions written in a binary machine language. ANS: T 6. A bit that is turned off is represented by the value -1. ANS: F 7. The main reason to use secondary storage is to hold data for long periods of time, even when the power supply to the computer is turned off. ANS: T 8. RAM is a volatile memory used for temporary storage while a program is running. ANS: T 9. The Python language uses a compiler which is a program that both translates and executes the instructions in a high-level language. ANS: F 10. IDLE is an alternative method to using a text editor to write, execute, and test a Python program. ANS: T
MULTIPLE CHOICE 1. Programs are commonly referred to as a. b. c. d.
system software software application software utility programs
ANS: B 2. Which of the following is considered to be the world's first programmable electronic computer? a. b. c. d.
IBM Dell ENIAC Gateway
ANS: C 3. Where does a computer store a program and the data that the program is working with while the program is running? a. b. c. d.
in main memory in the CPU in secondary storage in the microprocessor
ANS: A 4. What type of volatile memory is usually used only for temporary storage while running a program? a. b. c. d.
ROM TMM RAM TVM
ANS: C 5. Modern CPUs are much _______________ than the CPUs of early computers. a. b. c. d.
larger and more powerful smaller and more powerful less powerful slower
ANS: B 6. Which computer language uses short words known as mnemonics for writing programs? a. b. c. d.
Assembly Java Pascal Visual Basic
ANS: A
7. The process known as the __________ cycle is used by the CPU to execute instructions in a program. a. b. c. d.
decode-fetch-execute decode-execute-fetch fetch-decode-execute fetch-execute-decode
ANS: C 8. Which language is referred to as a low-level language? a. b. c. d.
C++ Assembly language Java Python
ANS: B 9. The following is an example of an instruction written in which computer language? 10110000 a. b. c. d.
Assembly language Java machine language C#
ANS: C 10. The encoding technique used to store negative numbers in the computer's memory is called a. b. c. d.
Unicode ASCII floating-point notation two's complement
ANS: D 11. The __________ coding scheme contains a set of 128 numeric codes that are used to represent characters in the computer's memory. a. b. c. d.
Unicode ASCII ENIAC two's complement
ANS: B 12. The smallest storage location in a computer's memory is known as a a. b. c. d.
byte ketter switch bit
ANS: D 13. What is the largest value that can be stored in one byte? a. 255
b. 128 c. 8 d. 65535 ANS: A 14. The disk drive is a secondary storage device that stores data by __________ encoding it onto a spinning circular disk. a. b. c. d.
electrically magnetically digitally optically
ANS: B 15. A __________ has no moving parts and operates faster than a traditional disk drive. a. b. c. d.
DVD drive solid state drive jumper drive hyper drive
ANS: B 16. Which of the following is not a major component of a typical computer system? a. b. c. d.
the CPU main memory the operating system secondary storage devices
ANS: C 17. Which type of error prevents the program from running? a. b. c. d.
syntax human grammatical logical
ANS: A 18. What is the decimal value of the following binary number? 10011101 a. b. c. d.
157 8 156 28
ANS: C MULTIPLE RESPONSE 1. Select all that apply. To create a Python program you can use a. a text editor
b. a word processor if you save your file as a .docx c. IDLE d. Excel ANS: A, C COMPLETION 1. A(n) ___________ is a set of instructions that a computer follows to perform a task. ANS: program 2. The term ___________ refers to all the physical devices that make up a computer. ANS: hardware 3. The __________ is the part of the computer that actually runs programs and is the most important component in a computer. ANS: central processing unit, CPU 4. A disk drive stores data by __________ encoding it onto a circular disk. ANS: magnetically 5. __________ are small central processing unit chips. ANS: Microprocessors 6. __________ is a type of memory that can hold data for long periods of time, even when there is no power to the computer. ANS: Secondary storage 7. Main memory is commonly known as __________. ANS: random-access memory, RAM 8. USB drives store data using __________ memory. ANS: flash 9. The Python __________ is a program that can read Python programming statements and execute them. ANS: interpreter 10. In __________ mode, the interpreter reads the contents of a file that contains Python statements and executes each statement. ANS: script
Starting Out with Python 5e (Gaddis) Chapter 2 Input, Processing, and Output TRUE/FALSE 1. Comments in Python begin with the # character. ANS: T 2. When using the camelCase naming convention, the first word of the variable name is written in lowercase and the first characters of all subsequent words are written in uppercase. ANS: T 3. According to the behavior of integer division, when an integer is divided by an integer, the result will be a float. ANS: F 4. Python allows programmers to break a statement into multiple lines. ANS: T 5. Python formats all floating-point numbers to two decimal places when outputting with the print statement. ANS: F 6. A flowchart is a tool used by programmers to design programs. ANS: T 7. In Python, math expressions are always evaluated from left to right, no matter what the operators are. ANS: F 8. Computer programs typically perform three steps: input is received, some process is performed on the input, and output is produced. ANS: T 9. In Python, print statements written on separate lines do not necessarily output on separate lines. ANS: T 10. The \t escape character causes the output to skip over to the next horizontal tab.
ANS: T 11. Since a named constant is just a variable, it can change any time during a program's execution. ANS: F MULTIPLE CHOICE 1. What is the informal language, used by programmers use to create models of programs, that has no syntax rules and is not meant to be compiled or executed? a. b. c. d.
flowchart algorithm source code pseudocode
ANS: D 2. A(n) __________ is a diagram that graphically depicts the steps that take place in a program? a. b. c. d.
flowchart algorithm source code pseudocode
ANS: A 3. The __________ function reads a piece of data that has been entered at the keyboard and returns that piece of data, as a string, back to the program. a. b. c. d.
input() output() eval_input() str_input()
ANS: A 4. The line continuation character is a a. b. c. d.
# % & \
ANS: D 5. Which mathematical operator is used to raise 5 to the second power in Python? a. b. c. d.
/ ** ^ ~
ANS: B 6. In a print statement, you can set the __________ argument to a space or empty string to stop the output from advancing to a new line.
a. b. c. d.
stop end separator newLine
ANS: B 7. After the execution of the following statement, the variable sold will reference the numeric literal value as (n) __________ data type. sold = 256.752 a. b. c. d.
int float str currency
ANS: B 8. After the execution of the following statement, the variable price will reference the value __________. price = int(68.549) a. b. c. d.
68 69 68.55 68.6
ANS: A 9. What is the output of the following statement? print('I\'m ready to begin') a. b. c. d.
Im ready to begin I\'m ready to begin I'm ready to begin 'I\'m ready to begin'
ANS: C 10. What is the output of the following statement, given that value1 = 2.0 and value2 = 12? print(value1 * value2) a. b. c. d.
24 value1 * value2 24.0 2.0 * 12
ANS: C 11. What is the output of the following statement? print('The path is D:\\sample\\test.') a. ‘The path is D:\\sample\\test.’ b. The path is D:\\sample\\test. c. The path is D\\sample\\test.
d. The path is D:\sample\test. ANS: D 12. What is the output of the following statement? print('One' 'Two' 'Three') a. One Two Three b. One Two Three c. OneTwoThree d. Nothing—This statement contains an error. ANS: C 13. The __________ built-in function is used to read a number that has been typed on the keyboard. a. b. c. d.
input() read() get() keyboard()
ANS: A 14. What is the output of the following code? val = 123.456789 print(f'{val:.3f}') a. 123 b. 123.457 c. 123.456 d. 123.456789 ANS: B 15. What is the output of the following code? val = 123456.789 print(f'{val:,.2f}') a. 123456.79 b. 123456.78 c. 123,456.78 d. 123,456.79 ANS: D 16. Which of the following will display 20%? a. print(f'{20:.0%}') b. print(f'{0.2:.0%}')
c. print(f'{0.2 * 100:.0%}') d. print(f'{0.2:%}') ANS: B 17. What symbol is used to mark the beginning and end of a string? a. b. c. d.
a slash (/) an asterisk (*) a quote mark (") a comma (,)
ANS: C 18. To use Python's turtle graphics, you must include which of the following statements in your program? a. b. c. d.
import turtle_module import turtle_graphics import turtle import Turtle
ANS: C 19. The Python turtle is initially positioned in the __________ of a graphics window and it first appears, by default, to be heading __________. a. b. c. d.
center, up top left corner, east bottom left corner, down center, east
ANS: D 20. You can use the _______________ turtle graphics command to get numeric input from the user and assign it to a variable. a. b. c. d.
turtle.numinput turtle.getnum turtle.inputnum turtle.dialog
ANS: A MULTIPLE RESPONSE 1. Select all that apply. Which of the following are steps in the program development cycle? a. b. c. d.
design the program write the code and correct syntax errors test the program correct logic errors
ANS: A, B, C, D 2. Select all that apply. Assume you are writing a program that calculates a user's total order cost that includes sales tax of 6.5%. Which of the following are advantages of using a named constant to represent the sales tax instead of simply entering 0.065 each time the tax is required in the code?
a. It will be easier for another programmer who may need to use this code to understand the purpose of the number wherever it is used in the code. b. If the tax amount changes to 7.0%, the value will only have to be changed in one place. c. It allows the end-user to always see the value of the sales tax. d. It avoids the risk that any change to the value of sales tax will be made incorrectly or that an instance of the tax value might be missed as might occur if the number had to be changed in multiple locations. ANS: A, B, D COMPLETION 1. ___________ are notes of explanation that document lines or sections of a program. ANS: Comments 2. The % symbol is the remainder operator, also known as the ___________ operator. ANS: modulus, mod 3. A(n) __________ character is a special character that is preceded with a backslash (\), appearing inside a string literal. ANS: escape 4. The __________ specifier is a special set of characters that specify how a value should be formatted. ANS: formatting 5. When applying the .3f formatting specifier to the number 76.15854, the result is __________. ANS: 76.159 6. A(n) __________ is a single task that the program must perform in order to satisfy the customer. ANS: software requirement 7. In the expression 12.45 + 3.6, the values to the right and left of the + symbol are the __________. ANS: operands 8. A(n) __________ is a name that represents a value stored in the computer's memory. ANS: variable 9. Python uses __________ to categorize values in memory. ANS: data types 10. When the + operator is used with two strings, it performs string __________. ANS: concatenation
11. A __________ is a name that represents a value the cannot be changed during a program's execution. ANS: named constant
Starting Out with Python 5e (Gaddis) Chapter 3 Decision Structures and Boolean Logic TRUE/FALSE 1. The Python language is not sensitive to block structuring of code. ANS: F 2. The if statement causes one or more statements to execute only when a Boolean expression is true. ANS: T 3. Python allows you to compare strings, but it is not case sensitive. ANS: F 4. Nested decision statements are one way to test more than one condition. ANS: T 5. Python uses the same symbols for the assignment operator as for the equality operator. ANS: F 6. The not operator is a unary operator which must be used in a compound expression. ANS: F 7. Short -circuit evaluation is only performed with the not operator. ANS: F 8. Expressions that are tested by the if statement are called Boolean expressions. ANS: T 9. Decision structures are also known as selection structures. ANS: T 10. An action in a single alternative decision structure is performed only when the condition is true. ANS: T 11. The following statement will check to see if the turtle's pen color is 'green': if turtle.pencolor() = 'green':
ANS: F 12. The following code snippet will change the turtle's pen size to 4 if it is presently less than 4: if turtle.pensize() < 4: turtle.pensize(4) ANS: T MULTIPLE CHOICE 1. A(n) __________ structure is a logical design that controls the order in which a set of statements execute. a. b. c. d.
function control sequence iteration
ANS: B 2. The decision structure that has two possible paths of execution is known as a. b. c. d.
single alternative double alternative dual alternative two alternative
ANS: C 3. Multiple Boolean expressions can be combined by using a logical operator to create __________ expressions. a. b. c. d.
sequential logical compound mathematical
ANS: C 4. When using the __________ logical operator, one or both of the subexpressions must be true for the compound expression to be true. a. b. c. d.
or and not maybe
ANS: A 5. Which logical operators perform short-circuit evaluation? a. b. c. d.
or, not not, and or, and and, or, not
ANS: C 6. Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive? a. b. c. d.
if 10 < y or y > 50: if 10 > y and y < 50: if y >= 10 and y <= 50: if y >= 10 or y <= 50:
ANS: C 7. A Boolean variable can reference one of two values which are a. b. c. d.
yes or no True or False T or F Y or N
ANS: B 8. What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y or z > x a. b. c. d.
True False 8 5
ANS: A 9. What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y and z > x a. b. c. d.
True False 8 5
ANS: B 10. What is the result of the following Boolean expression, given that x = 5, y = 3, and z= 8? not (x < y or z > x) and y < z a. b. c. d.
True False 8 5
ANS: B 11. What does the following expression mean? x <= y a. x is less than y
b. x is less than or equal to y c. x is greater than y d. x is greater than or equal to y ANS: B 12. Which of the following is the correct if clause to determine whether choice is anything other than 10? a. b. c. d.
if choice != 10: if choice != 10 if choice <> 10: if not(choice < 10 and choice > 10):
ANS: A 13. When using the __________ logical operator, both subexpressions must be true for the compound expression to be true. a. b. c. d.
or and not either or or and
ANS: B 14. In Python the __________ symbol is used as the not-equal-to operator. a. b. c. d.
== <> <= !=
ANS: D 15. In Python the __________ symbol is used as the equality operator. a. b. c. d.
== <> <= !=
ANS: A 16. Which of the following will hide the turtle if it is visible? a. if turtle.isvisible(): turtle.invisible() b. if turtle.isvisible turtle.hideturtle() c. turtle.isvisible(): turtle.hide() d. if turtle.isvisible(): turtle.hideturtle() ANS: D
17. Which of the following will determine if the turtle's pen is up and will change it to down if that is the case? a. if turtle.isup(): turtle.isdown() b. if turtle.isdown turtle.penup() c. if not(turtle.isdown()): turtle.pendown() d. if not(turtle.penup()) turtle.penup() ANS: C COMPLETION 1. The ___________ statement is used to create a decision structure. ANS: if 2. In flowcharting, the __________ symbol is used to represent a Boolean expression. ANS: diamond 3. A(n) __________ decision structure provides only one alternative path of execution. ANS: single alternative 4. In a decision structure, the action is ___________ executed because it is performed only when a specific condition is true. ANS: conditionally 5. A(n) __________ operator determines whether a specific relationship exists between two values. ANS: relational 6. A(n) __________ statement will execute one block of statements if its condition is true or another block if its condition is false. ANS: if-else 7. Python provides a special version of a decision structure known as the __________ statement, which makes the logic of the nested decision structure simpler to write. ANS: if-elif-else 8. The logical __________ operator reverses the truth of a Boolean expression. ANS: not
9. Boolean variables are commonly used as __________ to indicate whether a specific condition exists. ANS: flags 10. A(n) ___________ expression is made up of two or more Boolean expressions. ANS: compound 11. The turtle.isdown() function returns ___________ if the turtle's pen is down. ANS: True
Starting Out with Python 5e (Gaddis) Chapter 4 Repetition Structures TRUE/FALSE 1. Reducing duplication of code is one of the advantages of using a loop structure. ANS: T 2. A good way to repeatedly perform an operation is to write the statements for the task once and then place the statements in a loop that will repeat as many times as necessary. ANS: T 3. In a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested. ANS: T 4. The first line in a while loop is referred to as the condition clause. ANS: F 5. In Python, an infinite loop usually occurs when the computer accesses an incorrect memory address. ANS: F 6. Both of the following for clauses would generate the same number of loop iterations. for num in range(4): for num in range(1, 5): ANS: T 7. The integrity of a program's output is only as good as the integrity of its input. For this reason, the program should discard input that is invalid and prompt the user to enter valid data. ANS: T 8. Functions can be called from statements in the body of a loop and loops can be called from within the body of a function. ANS: F 9. In a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop. ANS: T
10. To get the total number of iterations in a nested loop, add the number of iterations in the inner loop to the number in the outer loop. ANS: F 11. A while loop is called a pretest loop because the condition is tested after the loop has had one iteration. ANS: F 12. In order to draw an octagon with turtle graphics, you would need a loop that iterates eight times. ANS: T MULTIPLE CHOICE 1. What type of loop structure repeats the code a specific number of times? a. b. c. d.
condition-controlled loop number-controlled loop count-controlled loop Boolean-controlled loop
ANS: C 2. What type of loop structure repeats the code based on the value of Boolean expression? a. b. c. d.
condition-controlled loop number-controlled loop count-controlled loop Boolean-controlled loop
ANS: A 3. What are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2): a. b. c. d.
2, 3, 4, 5, 6, 7, 8, 9 2, 5, 8 2, 4, 6, 8 1, 3, 5, 7, 9
ANS: C 4. What are the values that the variable num contains through the iterations of the following for loop? for num in range(4): a. b. c. d.
1, 2, 3, 4 0, 1, 2, 3, 4 1, 2, 3 0, 1, 2, 3
ANS: D
5. Which of the following is not an augmented assignment operator? a. b. c. d.
*= /= += <=
ANS: D 6. A variable used to keep a running total is called a(n) a. b. c. d.
accumulator total running total summer
ANS: A 7. __________ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation. a. b. c. d.
Input validation Correcting data Data validation Correcting input
ANS: A 8. A(n) __________ structure is a structure that causes a statement or a set of statements to execute repeatedly. a. b. c. d.
sequence decision module repetition
ANS: D 9. The first operation is called the __________ and its purpose is to get the first input value that will be tested by the validation loop. a. b. c. d.
priming read first input loop set read loop validation
ANS: A 10. When will the following loop terminate? while keep_going != 999: a. b. c. d.
when keep_going refers to a value less than 999 when keep_going refers to a value greater than 999 when keep_going refers to a value equal to 999 when keep_going refers to a value not equal to 999
ANS: C
11. In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called a. b. c. d.
sequence variable value list
ANS: D 12. In Python, the variable in the for clause is referred to as the __________ because it is the target of an assignment at the beginning of each loop iteration. a. b. c. d.
target variable loop variable for variable count variable
ANS: A 13. Which of the following represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable number and the total is stored in the variable total? a. b. c. d.
total + number = total number += number total += number total = number
ANS: C 14. What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total) a. 1 3 6 b. 5 c. 1 4 d. 6 ANS: D 15. What will be displayed after the following code is executed? total = 0 for count in range(4,6): total += count print(total) a. 4 9 b. 4
5 6 c. 4 5 d. 9 ANS: A 16. What will be displayed after the following code is executed? count = 4 while count < 12: print("counting") count = count + 2 a. counting counting counting counting b. counting counting counting counting c. counting counting d. counting counting counting ANS: B 17. What will be displayed after the following code is executed? for num in range(0, 20, 5): num += num print(num) a. b. c. d.
30 25 0 5 10 15 20 5 10 15
ANS: A 18. What does the following program do? student = 1 while student <= 3: total = 0 for score in range(1, 4): score = int(input("Enter test score: ")) total += score average = total/3 print("Student ", student, "average: ", average) student += 1 a. It accepts 4 test scores for 3 students and outputs the average of the 12 scores.
b. It accepts 3 test scores for each of 3 students and outputs the average for each student. c. It accepts 4 test scores for 2 students, then averages and outputs all the scores. d. It accepts one test score for each of 3 students and outputs the average of the 3 scores. ANS: B COMPLETION 1. A(n) ___________ structure causes a set of statements to execute repeatedly. ANS: repetition 2. A(n) __________-controlled loop causes a statement or set of statements to repeat as long as the condition is true. ANS: condition 3. The while loop is known as a(n) __________ loop because it tests the condition before performing an iteration. ANS: pretest 4. A(n) ___________ loop usually occurs when the programmer does not include code inside the loop that makes the test condition false. ANS: infinite 5. In Python, you would use the __________ statement to write a count-controlled loop. ANS: for 6. A(n) __________ total is a sum of numbers that accumulates with each iteration of the loop. ANS: running 7. A(n) __________ is a special value that marks the end of a sequence of items. ANS: sentinel 8. The acronym __________ refers to the fact that the computer cannot tell the difference between good data and bad data. ANS: GIGO 9. A(n) __________ validation loop is sometimes called an error trap or an error handler. ANS: input 10. The ___________ function is a built-in function that generates a list of integer values. ANS: range 11. The following for loop iterates ___________ times to draw a square.
for x in range(4): turtle.forward(200) turtle.right(90) ANS: four, 4
Starting Out with Python 5e (Gaddis) Chapter 5 Functions TRUE/FALSE 1. Python function names follow the same rules as those for naming variables. ANS: T 2. The function header marks the beginning of the function definition. ANS: T 3. A function definition specifies what a function does and causes the function to execute. ANS: F 4. A hierarchy chart shows all the steps that are taken inside a function. ANS: F 5. The pass keyword is used to pass arguments to a function. ANS: F 6. A local variable can be accessed from anywhere in the program. ANS: F 7. Different functions can have local variables with the same names. ANS: T 8. Python allows you to pass multiple arguments to a function. ANS: T 9. To assign a value to a global variable in a function, the global variable must be first declared in the function. ANS: T 10. The value assigned to a global constant can be changed in the mainline logic. ANS: F 11. One reason not to use global variables is that it makes a program hard to debug.
ANS: T 12. A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it. ANS: T 13. Unlike other languages, in Python the number of values a function can return is limited to one. ANS: F 14. In Python you can have a list of variables on the left side of the argument operator. ANS: T 15. In Python there is no restriction on the name of a module file. ANS: F 16. One of the drawbacks of a modularized program is that the only structure you can use in such a program is the sequence structure. ANS: F 17. One reason to store graphics functions in a module is so that you can import the module into any program that needs to use those functions. ANS: T 18. The randrange function returns a randomly selected value from a specific sequence of numbers. ANS: T 19. The math function atan(x) returns one tangent of x in radians. ANS: F 20. The math function ceil(x) returns the smallest integer that is greater than or equal to x. ANS: T 21. Unfortunately, there is no way to store and call on functions when using turtle graphics. ANS: F MULTIPLE CHOICE
1. What is a group of statements that exists within a program for the purpose of performing a specific task? a. b. c. d.
a function a subtask a process a subprocess
ANS: A 2. The first line in a function definition is known as the function a. b. c. d.
header block return parameter
ANS: A 3. The __________ design technique can be used to break down an algorithm into functions. a. b. c. d.
subtask block top-down simplification
ANS: C 4. A set of statements that belong together as a group and contribute to the function definition is known as a a. b. c. d.
header block return parameter
ANS: B 5. A(n) __________ chart is also known as a structured chart. a. b. c. d.
flow data hierarchy organizational
ANS: C 6. The _____________ keyword is ignored by the Python interpreter and can be used as a placeholder for code that will be written later. a. placeholder b. pass c. pause d. skip ANS: B
7. A __________ variable is created inside a function. a. b. c. d.
global constant named constant local
ANS: D 8. The __________ of a local variable is the function in which that variable is created. a. b. c. d.
global reach definition space scope
ANS: D 9. A(n) __________ is any piece of data that is passed into a function when the function is called. a. b. c. d.
global variable argument local variable parameter
ANS: B 10. A(n) __________ is a variable that receives an argument that is passed into a function. a. b. c. d.
global variable argument named constant parameter
ANS: D 11. A __________ variable is accessible to all the functions in a program file. a. b. c. d.
keyword local global string
ANS: C 12. A __________ constant is a name that references a value that cannot be changed while the program runs. a. b. c. d.
keyword local global string
ANS: C 13. When a function is called by its name during the execution of a program, then it is a. executed b. located
c. defined d. exported ANS: A 14. It is recommended that programmers avoid using __________ variables in a program whenever possible. a. b. c. d.
local global string keyword
ANS: B 15. The Python library functions that are built into the Python __________ can be used by simply calling the required function. a. b. c. d.
code compiler linker interpreter
ANS: D 16. Python comes with __________ functions that have already been prewritten for the programmer. a. b. c. d.
standard library custom key
ANS: A 17. What type of function can be used to determine whether a number is even or odd? a. b. c. d.
even odd math Boolean
ANS: D 18. A value-returning function is a. b. c. d.
a single statement that performs a specific task called when you want the function to stop a function that will return a value back to the part of the program that called it a function that receives a value when called
ANS: C 19. Which of the following statements causes the interpreter to load the contents of the random module into memory? a. b. c. d.
load random import random upload random download random
ANS: B 20. Whic of the following will assign a random integer in the range of 1 through 50 to the variable number? a. b. c. d.
random(1, 50) = number number = random.randint(1, 50) randint(1, 50) = number number = random(range(1, 50))
ANS: B 21. What does the following statement mean? num1, num2 = get_num() a. b. c. d.
The function get_num() is expected to return a value for num1 and for num2. The function get_num() is expected to return one value and assign it to num1 and num2. This statement will cause a syntax error. The function get_num() will receive the values stored in num1 and num2.
ANS: A 22. What will display after the following code is executed? def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer if __name__ == '__main__': main() a. b. c. d.
70 25 100 The statement will cause a syntax error.
ANS: B 23. In a value-returning function, the value of the expression that follows the keyword __________ will be sent back to the part of the program that called the function. a. b. c. d.
def result sent return
ANS: D 24. The Python standard library's __________ module contains numerous functions that can be used in mathematical calculations. a. math b. string
c. random d. number ANS: A 25. Which of the following functions returns the largest integer that is less than or equal to its argument? a. b. c. d.
floor ceil lesser greater
ANS: A 26. What will be the output after the following code is executed? def pass_it(x, y): z = x + ", " + y return(z) name2 = "Julian" name1 = "Smith" fullname = pass_it(name1, name2) print(fullname) a. b. c. d.
Julian Smith Smith Julian Julian, Smith Smith, Julian
ANS: D 27. What will be the output after the following code is executed? def pass_it(x, y): z = x , ", " , y num1 = 4 num2 = 8 answer = pass_it(num1, num2) print(answer) a. b. c. d.
4, 8 8, 4 48 None
ANS: D 28. What will be the output after the following code is executed? def pass_it(x, y): z = y**x return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2)
print(answer) a. b. c. d.
81 64 12 None
ANS: B 29. What will be displayed after the following code is executed? def pass_it(x, y): z = x*y result = get_result(z) return(result) def get_result(number): z = number + 2 return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer) a. b. c. d.
12 9 14 Nothing, this code contains a syntax error.
ANS: C 30. What does the following program do? import turtle def main(): turtle.hideturtle() square(100,0,50,'blue') def square(x, y, width, color): turtle.penup() turtle.goto(x, y) turtle.fillcolor(color) turtle.pendown() turtle.begin_fill() for count in range(4): turtle.forward(width) turtle.left(90) turtle.end_fill() if __name__ == '__main__': main() a. It draws a blue square at coordinates (100, 0), 50 pixels wide, starting at the top right corner.
b. It draws a blue square at coordinates (0, 50), 100 pixels wide, starting at the top right corner. c. It draws a blue square at coordinates (100, 0), 50 pixels wide, in the lower-left corner. d. Nothing since you cannot call a function with turtle graphics. ANS: C 31. What does the following program do? import turtle def main(): turtle.hideturtle() square(100,0,50,'blue') def square(x, y, width, color): turtle.penup() turtle.goto(x, y) turtle.fillcolor(color) turtle.pendown() turtle.begin_fill() for count in range(2): turtle.forward(width) turtle.left(90) turtle.end_fill() if __name__ == '__main__': main() a. b. c. d.
It draws a blue square. It draws a blue triangle. It draws 2 blue lines. Nothing since you cannot call a function with turtle graphics.
ANS: B COMPLETION 1. The code for a function is known as a function ___________. ANS: definition 2. The function header begins with the keyword __________ and is followed by the name of the function. ANS: def 3. The main function contains a program's __________ logic which is the overall logic of the program. ANS: mainline 4. In a flowchart, a function call is depicted by a(n) ___________. ANS: rectangle
5. The top-down design breaks down the overall task of a program into a series of __________. ANS: subtasks 6. A(n) __________ chart is a visual representation of the relationships between functions. ANS: hierarchy 7. Arguments are passed by __________ to the corresponding parameter variables in a function. ANS: position 8. A variable is available only to statements in the variable's __________. ANS: scope 9. Functions that are in the standard library are stored in files that are known as __________. ANS: modules 10. To refer to a function in a module, Python uses ___________ notation. ANS: dot 11. A value-returning function has a(n) ___________ statement that sends a value back to the part of the program that called it. ANS: return 12. The ___________ chart is an effective tool used by programmers to design and document functions. ANS: IPO 13. The 'P' in the acronym IPO refers to ___________. ANS: processing 14. In Python, a module's file name should end in ___________. ANS: .py 15. The approach known as __________ makes a program easier to understand, test, and maintain. ANS: modularization 16. The return values of the trigonometric functions in Python are in __________. ANS: radians
Starting Out with Python 5e (Gaddis) Chapter 6 Files and Exceptions TRUE/FALSE 1. If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode, then an alert will appear on the screen. ANS: F 2. When a piece of data is read from a file, it is copied from the file into the program. ANS: F 3. Closing a file disconnects the communication between the file and the program. ANS: T 4. In Python, there is nothing that can be done if the program tries to access a file to read that does not exist. ANS: F 5. Python allows the programmer to work with text and number files. ANS: F 6. The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y if y = 0. ANS: T 7. An exception handler is a piece of code that is written using the try/except statement. ANS: T 8. If the last line in a file is not terminated with \n, the readline method will return the line without \n. ANS: T 9. Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written. ANS: T 10. It is possible to create a while loop that determines when the end of a file has been reached.
ANS: T MULTIPLE CHOICE 1. Which of the following is associated with a specific file and provides a way for the program to work with that file? a. b. c. d.
the filename the file extension the file object the file variable
ANS: C 2. What is the process of retrieving data from a file called? a. b. c. d.
retrieving data reading data reading input getting data
ANS: B 3. Which of the following describes what happens when a piece of data is written to a file? a. b. c. d.
The data is copied from a variable in RAM to a file. The data is copied from a variable in the program to a file. The data is copied from the program to a file. The data is copied from a file object to a file.
ANS: A 4. Which step creates a connection between a file and a program? a. b. c. d.
open the file read the file process the file close the file
ANS: A 5. How many types of files are there? a. b. c. d.
one two three more than three
ANS: B 6. A(n) __________ access file is also known as a direct access file. a. b. c. d.
sequential random numbered text
ANS: B 7. Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it? a. b. c. d.
sequential random numbered text
ANS: B 8. A single piece of data within a record is called a a. b. c. d.
variable delimiter field data bit
ANS: C 9. Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist? a. b. c. d.
'w' 'r' 'a' 'e'
ANS: A 10. Which mode specifier will open a file but not let you change the file or write to it? a. b. c. d.
'w' 'r' 'a' 'e'
ANS: B 11. Which method could be used to strip specific characters from the end of a string? a. b. c. d.
estrip rstrip strip remove
ANS: B 12. Which method could be used to convert a numeric value to a string? a. b. c. d.
str value num chr
ANS: A 13. Which method will return an empty string when it has attempted to read beyond the end of a file?
a. b. c. d.
read getline input readline
ANS: D 14. Which statement can be used to handle some of the runtime errors in a program? a. b. c. d.
an exception statement a try statement a try/except statement an exception handler statement
ANS: C 15. Given that the customer file references a file object, and the file was opened using the 'w' mode specifier, how would you write the string 'Mary Smith' to the file? a. b. c. d.
customer file.write('Mary Smith') customer.write('w', 'Mary Smith') customer.input('Mary Smith') customer.write('Mary Smith')
ANS: D 16. When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string? a. b. c. d.
write input get read
ANS: D 17. Which of the following is the correct way to open a file named users.txt in 'r' mode? a. b. c. d.
infile = open('r', users.txt) infile = read('users.txt', 'r') infile = open('users.txt', 'r') infile = readlines('users.txt', r)
ANS: C 18. Which of the following is the correct way to open a file named users.txt to write to it? a. b. c. d.
outfile = open('w', users.txt) outfile = write('users.txt', 'w') outfile = open('users.txt', 'w') outfile = open('users.txt')
ANS: C 19. What will be the output after the following code is executed and the user enters 75 and 0 at the first two prompts? def main():
try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') if __name__ == '__main__': main() a. b. c. d.
ERROR: cannot have 0 items ERROR: number of items can't be negative 0 Nothing; there is no print statement to display average.
ANS: A 20. What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') if __name__ == '__main__': main() a. ERROR: cannot have 0 items b. ERROR: cannot have 0 items ERROR: number of items can't be negative c. ERROR: number of items can't be negative d. Nothing; there is no print statement to display average. The ValueError will not catch the error. ANS: D COMPLETION 1. When a program needs to save data for later use, it writes the data in a(n) ___________. ANS: file 2. Programmers usually refer to the process of __________ data in a file as writing data to the file. ANS: saving
3. When data is written to a file, it is described as a(n) __________ file. ANS: output 4. If data is retrieved from a file by a program, this is known by the term __________ file. ANS: input 5. A(n) ___________ file contains data that has been encoded as text, using a scheme such as ASCII. ANS: text 6. A(n) ___________ access file retrieves data from the beginning of the file to the end of the file. ANS: sequential 7. A(n) __________ file contains data that has not been converted to text. ANS: binary 8. A filename __________ is a short sequence of characters that appear at the end of a filename, preceded by a period. ANS: extension 9. A(n) __________ gives information about the line number(s) that caused an exception. ANS: traceback 10. A(n) ___________ block includes one or more statements that can potentially raise an exception. ANS: try block
Starting Out with Python 5e (Gaddis) Chapter 7 Lists and Tuples TRUE/FALSE 1. Invalid indexes do not cause slicing expressions to raise an exception. ANS: T 2. Lists are dynamic data structures such that items may be added to them or removed from them. ANS: T 3. Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures. ANS: F 4. A list cannot be passed as an argument to a function. ANS: F 5. The remove method removes all occurrences of an item from a list. ANS: F 6. The sort method rearranges the elements of a list so they are in ascending or descending order. ANS: F 7. The index of the first element in a list is 1, the index of the second element is 2, and so forth. ANS: F 8. The index -1 identifies the last element in a list. ANS: T 9. To calculate the average of the numeric values in a list, the first step is to get the total of values in the list. ANS: T 10. In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead. ANS: T
11. In order to create graphs using the matplotlib package, you need to import the pyplot module. ANS: T 12. To add a descriptive label to the X and Y axes of a graph when using the matplotlib package, you need to import the labels module. ANS: F MULTIPLE CHOICE 1. What are the data items in a list called? a. b. c. d.
data elements items values
ANS: B 2. When working with multiple sets of data, one would typically use a(n) a. b. c. d.
list tuple nested list sequence
ANS: C 3. The primary difference between a tuple and a list is that a. b. c. d.
you don't use commas to separate elements in a tuple a tuple can only include string elements a tuple cannot include lists as elements once a tuple is created, it cannot be changed
ANS: D 4. What is an advantage of using a tuple rather than a list? a. b. c. d.
Tuples are not limited in size. Tuples can include any data as an element. Processing a tuple is faster than processing a list. There is never an advantage to using a tuple.
ANS: C 5. Which list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2) a. b. c. d.
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 3, 5, 7, 9] [2, 4, 6, 8] [0, 2, 4, 6, 8]
ANS: D 6. Which of the following would you use if an element is to be removed from a specific index? a. b. c. d.
a del statement a remove method an index method a slice method
ANS: A 7. What is the first negative index in a list? a. b. c. d.
0 -1 -0 the size of the list minus 1
ANS: B 8. Which method can be used to place an item at a specific index in a list? a. b. c. d.
append index insert add
ANS: C 9. Which method or operator can be used to concatenate lists? a. b. c. d.
* + % concat
ANS: B 10. Which method can be used to convert a list to a tuple? a. b. c. d.
append tuple insert list
ANS: B 11. Which method can be used to convert a tuple to a list? a. b. c. d.
append tuple insert list
ANS: D 12. What will be the value of the variable list after the following code executes?
list = [1, 2] list = list * 3 a. b. c. d.
[1, 2] * 3 [3, 6] [1, 2, 1, 2, 1, 2] [1, 2], [1, 2], [1, 2]
ANS: C 13. What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10 a. b. c. d.
[1, 2, 3, 10] [1, 2, 10, 4] [1, 10, 10, 10] Nothing; this code is invalid
ANS: A 14. What will be the value of the variable list2 after the following code executes? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6] a. b. c. d.
[1, 2, 3] [4, 5, 6] [1, 2, 3, 4, 5, 6] Nothing; this code is invalid
ANS: A 15. This function in the random module returns a random element from a list. a. choice b. choices c. sample d. random_element ANS: A 16. This function in the random module returns multiple, nonduplicated random elements from a list. a. choice b. choices c. sample d. random_element ANS: B 17. What values will list2 contain after the following code executes? list1 = [1, 2, 3] list2 = [item + 1 for item in list1]
a. [1, 2, 3] b. [2, 3, 4] c. [6, 7, 8] d. [[1, 2, 3],[2, 3, 4],[3, 4, 5]] ANS: B 18. What values will list2 contain after the following code executes? list1 = [1, 10, 3, 6] list2 = [item * 2 for item in list1 if item > 5] a. [2, 20, 6, 12] b. [10, 6] c. [20, 12] d. [[1, 10, 3, 6],[1, 10, 3, 6]] ANS: C 19. In order to create a graph in Python, you need to include a. b. c. d.
import matplotlib import pyplot import matplotlib.pyplot import matplotlib import pyplot
ANS: C 20. What will be the output after the following code is executed? import matplotlib.pyplot as plt def main(): x_crd = [0, 1 , 2, 3, 4, 5] y_crd = [2, 4, 5, 2] plt.plot(x_crd, y_crd) if __name__ == '__main__': main() a. b. c. d.
It will display a simple line graph. It will display a simple bar graph. Nothing; plt is not a Python method. Nothing; the number of x-coordinates do not match the number of y-coordinates.
ANS: D COMPLETION 1. A(n) __________ is an object that holds multiple items of data. ANS: sequence 2. Each element in a tuple has a(n) __________ that specifies its position in the tuple.
ANS: index 3. The built-in function __________ returns the length of a sequence. ANS: len 4. Tuples are __________ sequences which means that once a tuple is created, it cannot be changed. ANS: immutable 5. A(n) ___________ is a span of items that are taken from a sequence. ANS: slice 6. Lists are ___________, which means their elements can be changed in a program. ANS: mutable 7. The __________ method is commonly used to add items to a list. ANS: append 8. The __________ exception is raised when a search item is not in the list being searched. ANS: ValueError 9. The __________ method reverses the order of the items in a list. ANS: reverse 10. The __________ function returns the item that has the lowest value in the sequence. ANS: min 11. A list _____________ is a concise expression that creates a new list by iterating over the elements of an existing list. ANS: comprehension 12. The __________ package is a library you can use in Python to create two-dimensional charts and graphs. ANS: matplotlib 13. The ___________ function can be used to convert a list to a tuple. ANS: tuple
Starting Out with Python 5e (Gaddis) Chapter 8 More About Strings TRUE/FALSE 1. You cannot use a for loop to iterate over the characters in a string. ANS: F 2. Indexing works with both strings and lists. ANS: T 3. In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead. ANS: T 4. Indexing of a string starts at 1 so the index of the first character is 1, the index of the second character is 2, and so forth. ANS: F 5. The index -1 identifies the last character of a string. ANS: T 6. The following expression is valid: string[i] = 'i' ANS: F 7. The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr) ANS: F 8. If the + operator is used on strings, it produces a string that is a combination of the two strings used as its operands. ANS: T 9. When accessing each character in a string, such as for copying purposes, you would typically use a while loop.
ANS: F 10. If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences in the paragraph. ANS: T 11. The strip() method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters. ANS: F MULTIPLE CHOICE 1. What are the valid indexes for the string 'New York'? a. b. c. d.
0 through 7 0 through 8 -1 through -8 -1 through 6
ANS: A 2. What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print(mystr) a. b. c. d.
yes + no * 2 yes + no yes + no yesnono yesnoyesno
ANS: C 3. What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4] a. b. c. d.
'7' '1357' 5 '7 Country Ln.'
ANS: B 4. What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:] a. ' Country Ln.'
b. '1357' c. 'Coun' d. '57 C' ANS: A 5. What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:] a. b. c. d.
'135' '753' 'Ln.' 'y Ln'
ANS: C 6. What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2] a. b. c. d.
'0123456789' '24682468' '02468' '02020202020202020202'
ANS: C 7. If the start index is __________ the end index, the slicing expression will return an empty string. a. b. c. d.
equal to less than greater than less than or equal to
ANS: C 8. What is the return value of the string method lstrip()? a. b. c. d.
the string with all whitespaces removed the string with all leading whitespaces removed the string with all leading tabs removed the string with all leading spaces removed
ANS: B 9. What is the first negative index in a string? a. b. c. d.
0 -1 -0 the size of the string minus one
ANS: B 10. What will be assigned to the string variable pattern after the following code executes?
i = 3 pattern = 'z' * (5 * i) a. b. c. d.
'zzzzzzzzzzzzzzz' 'zzzzz' 'z * 15' Nothing; this code is invalid
ANS: A 11. Which method would you use to determine whether a certain substring is present in a string? a. b. c. d.
endswith(substring) find(substring) replace(string, substring) startswith(substring)
ANS: B 12. Which method would you use to determine whether a certain substring is the suffix of a string? a. b. c. d.
endswith(substring) find(substring) replace(string, substring) startswith(substring)
ANS: A 13. What list will be referenced by the variable list_strip after the following code executes? my_string = '03/07/2018' list_strip = my_string.split('/') a. b. c. d.
['3', '7', '2018'] ['03', '07', '2018'] ['3', '/', '7', '/', '2018'] ['03', '/', '07', '/', '2018']
ANS: B 14. What will be the value of the variable string after the following code executes? string = 'abcd' string.upper() a. b. c. d.
'abcd' 'ABCD' 'Abcd' Nothing; this code is invalid
ANS: B 15. What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!' a. 'Hello' b. ' world!'
c. 'Hello world!' d. Nothing; this code is invalid ANS: C 16. What will display after the following code executes? password = 'ILOVEPYTHON' if password.isalpha(): print('Invalid, must contain one number.') elif password.isdigit(): print('Invalid, must have one non-numeric character.') elif password.isupper(): print('Invalid, cannot be all uppercase characters.') else: print('Your password is secure!') a. Invalid, must contain one number. b. Invalid, must have one non-numeric character. c. Invalid, must contain one number. Invalid, cannot be all uppercase characters. d. Your password is secure! ANS: A COMPLETION 1. Each character in a string has a(n) __________ which specifies its position in the string. ANS: index 2. A(n) __________ exception will occur if you try to use an index that is out of range for a particular string. ANS: IndexError 3. The isalpha() method returns __________ if the string contains only alphabetic characters and is at least one character in length. ANS: True 4. A(n) __________ is a span of characters that are taken from within a string. ANS: slice 5. When the operand on the left side of the * symbol is a string and the operand on the right side is an integer, the * becomes the ___________ operator. ANS: repetition 6. The third number in string slicing brackets represents the ___________ value.
ANS: step 7. The __________ operator can be used to determine whether one string is contained in another string. ANS: in 8. The __________ method returns True if the string contains only numeric digits. ANS: isdigit() 9. The __________ method returns the list of the words in a string. ANS: split() 10. The __________ method returns a copy of the string with all the alphabetic letters converted to lower case. ANS: lower()
Starting Out with Python 5e (Gaddis) Chapter 9 Dictionaries and Sets TRUE/FALSE 1. You would typically use a for loop to iterate over the elements in a set. ANS: T 2. Sets are immutable. ANS: F 3. Sets are created using curly braces { }. ANS: F 4. The set remove and discard methods behave differently only when a specified item is not found in the set. ANS: T 5. A dictionary can include the same value several times but cannot include the same key several times. ANS: T 6. The union of two sets is a set that contains only the elements that appear in both sets. ANS: F 7. The difference of set1 and aet2 is a set that contains only the elements that appear in set1 but do not appear in set2. ANS: T 8. The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs. ANS: F 9. If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised. ANS: T 10. The issubset() method can be used to determine whether set1 is a subset of set2. ANS: T
11. A set comprehension is written just like a list comprehension, except that a set comprehension is enclosed in angled brackets (<>), and a list comprehension is enclosed in square brackets ([]). ANS: F MULTIPLE CHOICE 1. In a dictionary, you use a(n) __________ to locate a specific value. a. b. c. d.
datum element item key
ANS: D 2. What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)? a. b. c. d.
{ 1 ; 'January', 2 ; 'February', ... 12 ; 'December'} { 1 : 'January', 2 : 'February', ... 12 : 'December' } [ '1' : 'January', '2' : 'February', ... '12' : 'December' ] { 1, 2,... 12 : 'January', 'February',... 'December' }
ANS: B 3. What will be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] a. b. c. d.
False -1 0 KeyError
ANS: D 4. What is the number of the first index in a dictionary? a. b. c. d.
0 1 the size of the dictionary minus one Dictionaries are not indexed by number.
ANS: D 5. What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = 5556666' a. b. c. d.
{'John' : '5555555', 'Julie' : '5557777'} {'John' : '5556666', 'Julie' : '5557777'} {'John' : '5556666'} This code is invalid.
ANS: B
6. Which would you use to delete an existing key-value pair from a dictionary? a. b. c. d.
del remove delete unpair
ANS: A 7. Which would you use to get the number of elements in a dictionary? a. b. c. d.
size length len sizeof
ANS: C 8. Which method would you use to get all the elements in a dictionary returned as a list of tuples? a. b. c. d.
list items pop keys
ANS: B 9. Which method would you use to get the value associated with a specific key and remove that keyvalue pair from the dictionary? a. b. c. d.
list items pop popitem
ANS: C 10. What values will d2 contain after the following code executes? d = {1: 10, 2: 20, 3: 30} d2 = {k:v for k,v in d.items()} a. {10: 1, 20: 2, 30: 3} b. {1: 1, 2: 2, 3: 3} c. {10: 10, 20: 20, 30: 30} d. {1: 10, 2: 20, 3: 30} ANS: D 11. Which method can be used to add a group of elements to a set? a. b. c. d.
add addgroup update addset
ANS: C
12. In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the __________ operator. a. b. c. d.
included in isnotin isin
ANS: B 13. What does the get method do if the specified key is not found in the dictionary? a. b. c. d.
It throws an exception. It does nothing. It returns a default value. You cannot use the get method to specify a key.
ANS: C 14. Which of the following does not apply to sets? a. b. c. d.
The stored elements can be of different data types. All the elements must be unique; you cannot have two elements with the same value. The elements are unordered. The elements are in pairs.
ANS: D 15. What is the process used to convert an object to a stream of bytes that can be saved in a file? a. b. c. d.
pickling streaming writing dumping
ANS: A 16. What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities) a. b. c. d.
{'CA': 'Sacramento'} ['CA': 'Sacramento'] {'NY': 'Albany', 'GA': 'Atlanta'} {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}
ANS: D 17. What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL']
cities['FL'] = 'Tallahassee' print(cities) a. {'FL': 'Tallahassee'} b. KeyError c. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'} d. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} ANS: D 18. What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} if 'FL' in cities: del cities['FL'] cities['FL'] = 'Tallahassee' print(cities) a. {'FL': 'Tallahassee'} b. KeyError c. {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'} d. {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} ANS: C COMPLETION 1. A(n) __________ is an object that holds multiple unique items of data in an unordered manner. ANS: set 2. The built-in function, __________, returns the number of items in a set. ANS: len 3. To add a single item to a set, you can use the set __________ method. ANS: add 4. The __________ of two sets is a set that contains all the elements of both sets. ANS: union 5. Each element in a(n) __________ has two parts: a key and a value. ANS: dictionary 6. The elements in a dictionary are not stored in a specific order. Therefore, a dictionary is not a(n) ___________. ANS: sequence
7. To determine whether or not a key is included in a dictionary, or if an element is included in a set, you can use the ___________ operator. ANS: not in 8. The __________ method returns a value associated with a specific key and, if found, removes that key-value pair from the dictionary. ANS: pop 9. The __________ method clears the contents of a dictionary. ANS: clear 10. To write an object to a file, you use the __________ function of the __________ module. ANS: dump, pickle 11. The __________ method returns all of a dictionary's keys as a dictionary view. ANS: keys 12. Each element in a dictionary view is a __________. ANS: tuple
Starting Out with Python 5e (Gaddis) Chapter 10 Classes and Object-Oriented Programming TRUE/FALSE 1. A mutator method has no control over the way that a class's data attributes are modified. ANS: F 2. In a UML diagram the first section holds the list of the class's methods. ANS: F 3. Object-oriented programming allows us to hide the object's data attributes from code that is outside the object. ANS: T 4. Procedures operate on data items that are separate from the procedures. ANS: T 5. All instances of a class share the same values of the data attributes in the class. ANS: F 6. All class definitions are stored in the library so that they can be imported into any program. ANS: F 7. The self parameter is required in every method of a class. ANS: T 8. A class can be thought of as a blueprint that can be used to create an object. ANS: T 9. An object is a stand-alone program but is used by programs that need its service. ANS: F 10. The self parameter need not be named self but it is strongly recommended to do so, to conform with standard practice. ANS: T
MULTIPLE CHOICE 1. What does the acronym UML stand for? a. b. c. d.
Unified Modeling Language United Modeling Language Unified Model Language Union of Modeling Languages
ANS: A 2. Which section in the UML holds the list of the class's data attributes? a. b. c. d.
first section second section third section fourth section
ANS: B 3. Which section in the UML holds the list of the class's methods? a. b. c. d.
first section second section third section fourth section
ANS: C 4. What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method? a. b. c. d.
accessor mutator setter class
ANS: A 5. The procedures that an object performs are called a. b. c. d.
methods actions modules instances
ANS: A 6. Which attributes belong to a specific instance of a class? a. b. c. d.
instance self object data
ANS: A 7. What is the special name given to the method that returns a string containing an object's state?
a. b. c. d.
__state__ __obj__ __str__ __init__
ANS: C 8. Which method is automatically executed when an instance of a class is created in memory? a. b. c. d.
__state__ __obj__ __str__ __init__
ANS: D 9. Which method is automatically called when you pass an object as an argument to the print function? a. b. c. d.
__state__ __obj__ __str__ __init__
ANS: C 10. What type of programming contains class definitions? a. b. c. d.
procedural top-down object-oriented modular
ANS: C 11. Which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate on the data attributes? a. b. c. d.
a class an object an instance a module
ANS: B 12. Combining data and code in a single object is known as a. b. c. d.
modularity instantiation encapsulation objectification
ANS: C 13. Mutator methods are also known as a. b. c. d.
setters getters instances attributes
ANS: A 14. Accessor methods are also known as a. b. c. d.
setters getters instances attributes
ANS: B 15. When an object is passed as an argument, __________ is passed into the parameter variable. a. b. c. d.
a copy of the object a reference to the object's state a reference to the object Objects cannot be passed as arguments.
ANS: C 16. In object-oriented programming, one of first tasks of the programmer is to a. b. c. d.
list the nouns in the problem list the methods that are needed identify the classes needed identify the objects needed
ANS: C 17. Which is the first line needed when creating a class named Worker? a. b. c. d.
def__init__(self): class Worker: import random def worker_pay(self):
ANS: B 18. Which of the following will create an object, worker_joey, of the Worker class? a. b. c. d.
def__init__(worker_joey): class worker_joey: worker_joey = Worker() worker_joey.Worker
ANS: C COMPLETION 1. A(n) __________ is code that specifies the data attributes and methods for a particular type of object. ANS: class 2. Each object that is created from a class is called a(n) __________ of the class. ANS: instance
3. A class __________ is a set of statements that defines a class's methods and data attributes. ANS: definition 4. A(n) __________ method in a class initializes an object's data attributes. ANS: initializer 5. An object's __________ contains the values of the object's attributes at a given moment. ANS: state 6. A method that returns a value from a class's attribute but does not change it is known as a(n) __________ method. ANS: accessor 7. In ___________ programming, the programming is centered on objects that are created from abstract data types that encapsulate data and functions together. ANS: object-oriented 8. ___________ programming is a method of writing software that centers on the actions that take place in a program. ANS: Procedural 9. ___________ provides a set of standard diagrams for graphically depicting object-oriented systems. ANS: UML 10. The instance attributes are created by the __________ parameter and they belong to a specific instance of the class. ANS: self
Starting Out with Python 5e (Gaddis) Chapter 11 Inheritance TRUE/FALSE 1. New attributes and methods may be added to a subclass. ANS: T 2. One problem with using a UML diagram is that there is no way to indicate inheritance. ANS: F 3. When a class inherits another class, it is required to use all the data attributes and methods of the superclass. ANS: F 4. Polymorphism works on any two class methods that have the same name. ANS: T 5. A superclass inherits attributes and methods from its subclasses without any of them having to be rewritten. ANS: F 6. A subclass may not override any method other than the __init__ method. ANS: F 7. Each subclass has a method named __init__ that overrides the superclass's __init__ method. ANS: T 8. In a UML diagram depicting inheritance, you only need to write the name of the subclass. ANS: F 9. An "is a" relationship exists between a grasshopper and a bumblebee. ANS: F 10. An "is a" relationship exists between a wrench and a tool. ANS: T
MULTIPLE CHOICE 1. __________ allows a new class to inherit members of the class it extends. a. b. c. d.
Encapsulation Attributes Methods Inheritance
ANS: D 2. What gives a program the ability to call the correct method depending on the type of object that is used to call it? a. b. c. d.
Polymorphism Inheritance Encapsulation Methods
ANS: A 3. What does a subclass inherit from a superclass? a. b. c. d.
instances and attributes objects and methods methods and instances attributes and methods
ANS: D 4. In a UML diagram, what does the open arrowhead point to? a. b. c. d.
the superclass the subclass the object a method
ANS: A 5. When there are several classes that have many common data attributes, it is better to write a(n) __________ to hold all the general data. a. b. c. d.
superclass subclass object method
ANS: A 6. In an inheritance relationship, what is a specialized class called? a. b. c. d.
a superclass a subclass an object an instance
ANS: B 7. Base classes are also called
a. b. c. d.
superclasses derived classes subclasses class instances
ANS: A 8. What is the relationshop called in which one object is a specialized version of another object? a. b. c. d.
parent-child node-to-node is a class-subclass
ANS: C 9. __________ has the ability to define a method in a subclass and then define a method with the same name in a superclass. a. b. c. d.
Inheritance Encapsulation Polymorphism the 'is a' relationship
ANS: C 10. In the following line of code, what is the name of the subclass? class Rose(Flower): a. b. c. d.
Rose Flower Rose(Flower) None of these
ANS: A 11. In the following line of code, what is the name of the base class? class Python(Course): a. b. c. d.
Python Course Python(Course) None of these
ANS: B 12. Given the following line of code, in a UML diagram, what would the open arrowhead point to? class Celery(Vegetable): a. b. c. d.
Celery Vegetable class Celery(Vegetable)
ANS: B 13. Of the two classes, Cherry and Flavor, which would most likely be the subclass?
a. b. c. d.
Cherry Flavor either one neither; these are inappropriate class or subclass names
ANS: A 14. Which method can you use to determine whether an object is an instance of a class? a. b. c. d.
isinstance isclass isobject issubclass
ANS: A 15. Which of the following is the correct syntax for defining a class, table, which inherits from the furniture class? a. b. c. d.
class furniture[table]: class table.furniture: class furniture(table): class table(furniture):
ANS: D 16. Given the following beginning of a class definition for a superclass named clock, how many accessor and mutator methods will be needed to complete the class definition? class clock: def __init__(self, shape, color, price): self._shape = shape self.color = color self.price = price a. b. c. d.
1 mutator, 1 accessor 3 mutator, 4 accessor 3 mutator, 3 accessor 4 mutator, 5 accessor
ANS: C COMPLETION 1. __________ allows subclasses to have methods with the same names as methods in their superclasses. ANS: Polymorphism 2. The __________ function determines whether or not an object is an instance of a specific class or an instance of a subclass of that class. ANS: isinstance 3. A subclass is also called a(n) __________ class. ANS: derived
4. A superclass is also called a(n) __________ class. ANS: base 5. When a subclass method has the same name as a superclass method, the subclass method __________ the superclass method. ANS: overrides 6. In an inheritance relationship, the extended class is called the __________. ANS: subclass 7. New attributes and methods may be added to a subclass which makes it a(n) __________ version of the superclass. ANS: specialized 8. In an inheritance relationship, a minivan can be thought of as a(n) ___________ of the vehicles class. ANS: subclass, derived class 9. The term ___________ refers to an object's ability to take different forms. ANS: polymorphism 10. In a UML diagram, a line with an open arrowhead from a subclass to a superclass indicates ___________. ANS: inheritance
Starting Out with Python 5e (Gaddis) Chapter 12 Recursion TRUE/FALSE 1. A recursive function must have some way to control the number of times it repeats. ANS: T 2. In many cases it is easier to see how to solve a problem with recursion than with a loop. ANS: F 3. If a recursive solution is evident for a particular problem, and if the recursive algorithm does not slow system performance by an intolerable amount, then recursion would probably be a good design choice. ANS: T 4. A base case is not necessary for all recursive algorithms. ANS: F 5. There must be only one function involved in any recursive solution. ANS: F 6. Each time a function is called in a recursive solution, the system incurs overhead that is not incurred with a loop. ANS: T 7. When, in a recursive solution, function A calls function B which, in turn, calls function A, this is known as indirect recursion. ANS: T 8. A problem can normally be solved with recursion if it can be broken down into smaller problems that are identical in structure to the overall problem. ANS: T 9. Recursive algorithms are always more concise and efficient than iterative algorithms. ANS: F 10. Recursion is sometimes required to solve certain types of problems.
ANS: F MULTIPLE CHOICE 1. In a recursive solution, if the problem cannot be solved now, then a recursive function reduces it to a smaller but similar problem and a. b. c. d.
exits returns to the main function returns to the calling function calls itself to solve the smaller problem
ANS: D 2. What is the first step to take in order to apply a recursive approach? a. b. c. d.
Identify at least one case in which the problem can be solved without recursion. Determine a way to solve the problem in all circumstances using recursion. Identify a way to stop the recursion. Determine a way to return to the main function.
ANS: A 3. What is the second step to take in order to apply a recursive approach? a. Identify at least one case in which the problem can be solved without recursion. b. Determine a way to use recursion to solve the problem in all circumstances which cannot be solved without recursion. c. Determine a way to return to the main function. d. Identify a way to stop the recursion. ANS: B 4. If, in a recursive solution, function A calls function B which calls function C, this is called __________ recursion. a. b. c. d.
continuous direct three function call indirect
ANS: D 5. A problem can be solved with recursion if it can be broken down into __________ problems. a. b. c. d.
smaller one-line manageable modular
ANS: A 6. The base case is the case in which the problem can be solved without a. b. c. d.
loops decisions objects recursion
ANS: D 7. If a problem can be solved immediately without recursion, then the recursive function a. b. c. d.
solves it and returns exits returns a default value generates a run-time error
ANS: A 8. The process of calling a function requires a. b. c. d.
a slow memory access a quick memory access several actions to be performed by the computer one action to be performed by the computer
ANS: C 9. Which of the following describes the base case in a recursive solution? a. b. c. d.
a case in which the problem can be solved without recursion the case in which the problem is solved through recursion the way to stop the recursion the way to return to the main function
ANS: A 10. Recursion is a. b. c. d.
never required to solve a problem required to solve certain mathematical problems sometimes required to solve string problems required to solve some problems
ANS: A 11. A function is called from the main function for the first time and then calls itself seven times. What is the depth of recursion? a. b. c. d.
8 2 1 7
ANS: D 12. What defines the depth of recursion? a. b. c. d.
the length of the algorithm the number of function calls the number of times the function calls itself the number of times the function goes to the base case
ANS: C 13. Recursive functions are __________ iterative algorithms.
a. b. c. d.
more efficient than less efficient than as efficient as impossible to compare to
ANS: B 14. A recursive function includes __________ which are not necessary in a loop structure. a. b. c. d.
function calls conditional clauses overhead actions object instances
ANS: C 15. Which would be the base case in a recursive solution to the problem of finding the factorial of a number. Recall that the factorial of a non-negative whole number is defined as n! where: If n = 0, then n! = 1 If n > 0, then n! = 1 x 2 x 3 x ... x n a. b. c. d.
n=0 n=1 n>0 The factorial of a number cannot be solved with recursion.
ANS: A COMPLETION 1. All the cases of a recursive solution other than the base case are called the __________ case. ANS: recursive 2. The base case does not require __________, so it stops the chain of recursive calls. ANS: recursion 3. Recursive function calls are __________ efficient than loops. ANS: less 4. Each time a function is called, the system incurs __________ that is not necessary with a loop. ANS: overhead 5. A solution using a(n) __________ is usually more evident than a recursive solution. ANS: loop 6. A function is called from the main function and then it calls itself five times. The depth of recursion is __________. ANS: five
7. The majority of repetitive programming tasks are best done with ___________. ANS: loops 8. A recursion in which a function directly calls itself is known as ___________ recursion. ANS: direct 9. Usually a problem solved by recursion is reduced by making the value of one or more parameters __________ with each recursive call. ANS: smaller 10. Some problems are more __________ solved with recursion than with a loop. ANS: easily
Starting Out with Python 5e (Gaddis) Chapter 13 GUI Programming TRUE/FALSE 1. Python does not have GUI programming features built into the language itself. ANS: T 2. Programs that use tkinter do not always run reliably in IDLE. ANS: T 3. A root widget's destroy method can be used as a callback function for a Quit button. ANS: T 4. Radio buttons can be used to allow the user to make multiple selections at one time. ANS: F 5. Checkbutton widgets are displayed in groups and used to make mutually exclusive selections. ANS: F 6. In a GUI environment, no text input is possible. ANS: F 7. The pack method determines where a widget should be positioned. ANS: T 8. An info dialog box is a window that displays a message to the user and has an OK button which, when clicked, closes the dialog box. ANS: T 9. To use an Entry widget to get data entered by a user, you must use the Entry widget's set method. ANS: F 10. The Entry widget's get method retrieves either numeric or string data. ANS: F 11. To use the showinfo function, the tkinter.messagebox module must be imported.
ANS: T 12. By default, a Listbox widget does not display scrollbars. ANS: T 13. You can add different amounts of padding to each side of a widget. ANS: T 14. The point (0,0) represents the same place in a window with the Canvas widget as with turtle graphics. ANS: F MULTIPLE CHOICE 1. What are the items that appear on the graphical interface window called? a. b. c. d.
buttons icons widgets graphical elements
ANS: C 2. A __________ program is an event-driven program. a. b. c. d.
GUI command line procedural modular
ANS: A 3. Which widget allows the user to select a value by moving a slider along a track? a. b. c. d.
Scrollbar Toplevel Scale Slider
ANS: C 4. Which widget will display multiple lines of text? a. b. c. d.
Label Canvas Message Text
ANS: C 5. Which widget creates an area that displays one line of text or an image? a. Label
b. Canvas c. Message d. Text ANS: A 6. Which widget allows the user to enter a single line of input from the keyboard? a. b. c. d.
Toplevel Entry Message Text
ANS: B 7. In an event-driven program, the __________ accepts the user's commands. a. b. c. d.
register CPU operating system GUI
ANS: C 8. In an event-driven environment, the user interacts with a. b. c. d.
the graphical unit the user interface the register the CPU
ANS: B 9. The acronym GUI stands for a. b. c. d.
Graphical User's Interface Graphical User Interface Graphical User Interaction Graphical Union Interface
ANS: B 10. In Python, what module is used to create a GUI program? a. b. c. d.
tkinter pygui python_gui pycanvas
ANS: A 11. In a GUI environment most interactions are done through small windows known as __________ that display information and allow the user to perform actions. a. b. c. d.
input boxes windows dialog boxes message boxes
ANS: C 12. In a(n) __________ interface, a prompt is displayed that allows the user to enter a command which is then executed. a. b. c. d.
windows command line GUI operating
ANS: B 13. In a(n) __________ interface, the user can determine the order in which things happen. a. b. c. d.
windows command line GUI operating
ANS: C 14. A widget can appear with these types of padding. a. b. c. d.
internal and external upper and lower left and right north, south, east, and west
ANS: A 15. Which of these is not a valid relief style for borders? a. b. c. d.
flat raised sunken smooth
ANS: D 16. Which of the following is not a method of the Canvas widget? a. b. c. d.
create_line create_oval create_button create_text
ANS: C 17. A __________ widget displays a list of items and allows the user to select one or more items from the list. a. b. c. d.
Itembox SelectionList Menubox Listbox
ANS: D
18. A __________ is a container that can be used to organize the widgets in a window. a. b. c. d.
Textbox Label Frame Canvas
ANS: C 19. What is the default selection mode of a Listbox widget? a. b. c. d.
tkinter.BROWSE tkinter.EXTENDED tkinter.MULTIPLE tkinter.SINGLE
ANS: A 20. What does the Listbox widget's curselection method return? a. b. c. d.
A tuple containing the items that are currently selected in the Listbox Either True or False to indicate whether an item is currently selected A tuple containing the indexes of the items that are currently selected in the Listbox The item that is currently stored at index 0 in the Listbox
ANS: C 21. Which of the following must you include with your program so you can display a message to the user with the showinfo function? a. import tkinter b. import canvas import messagebox c. import messagebox d. import tkinter import tkinter.messagebox ANS: D 22. Given the following code, which line defines the size of the window? import tkinter class myShape: def __init__(self): self.main_window = tkinter.Tk() self.canvas = tkinter.Canvas(self.main_window, width=200, height=200) self.canvas.create_rectangle(30,30, 175, 175) self.canvas.pack() tkinter.mainloop() shape = myShape() a. self.main_window = tkinter.Tk() b. self.canvas = tkinter.Canvas(self.main_window,width=200, height=200)
c. self.canvas.create_rectangle(30,30, 175, 175) d. shape = myShape() ANS: B 23. Given the following code, what are the dimensions, in pixels, of the shape created? import tkinter class myShape: def __init__(self): self.main_window = tkinter.Tk() self.canvas = tkinter.Canvas(self.main_window, width=200, height=200) self.canvas.create_rectangle(30,30, 175, 175) self.canvas.pack() tkinter.mainloop() shape = myShape() a. b. c. d.
200 X 200 30 X 175 145 X 145 None of these
ANS: C COMPLETION 1. A(n) __________ allows the user to interact with the operating system and other programs through graphical elements on the screen. ANS: GUI 2. The GUI popularized the use of the __________ as an input device. ANS: mouse 3. __________ are small windows that display information and allow the user to perform actions. ANS: Dialog boxes 4. Since GUI programs respond to the actions of the user, they are called __________ programs. ANS: event-driven 5. The __________ module allows you to create GUI programs in Python. ANS: tkinter 6. The __________ widget is used to display text in a window. ANS: Label 7. The Label widget's __________ method determines where a widget should be positioned and makes the widget visible when the main window is displayed.
ANS: pack 8. A(n) ___________ is a container that can hold other widgets and organize the widgets in a window. ANS: Frame 9. A(n) __________ function is a function or method that executes when the user clicks a button. ANS: callback, event handler 10. A(n) __________ is a widget that the user can click to cause an action to occur. ANS: Button 11. To bind a callback function to a Listbox, you call the Listbox widget's _______ function. ANS: bind 12. You can remove an item from a Listbox by calling the Listbox widget's _______ method. ANS: delete 13. The __________ widget provides methods that allow the programmer to draw some simple shapes. ANS: Canvas 14. To create a line with the create_line method of the Canvas widget, you must include four arguments that represent beginning and ending __________. ANS: coordinates
Starting Out with Python 5e (Gaddis) Chapter 14 Database Programming TRUE/FALSE 1.
Although SQL is a language, you don't use it to write applications. ANS: T
2.
The columns in a table are assigned SQL data types. ANS: T
3.
The column that is designated as the primary key must hold a unique value for each row. ANS: T
4.
All identity columns in a table must contain the same value. ANS: F
5.
In SQLite, when you designate a column as INTEGER PRIMARY KEY, that column becomes an alias for the RowID column. ANS: T
6.
The SQL INSERT statement only inserts one row. ANS: F
7.
In SQLite, the Cursor object's fetchone method returns a list containing all the rows that result from a SELECT statement. ANS: F
8.
An SQL aggregate function performs a calculation on a set of values from a database table and returns a single value. ANS: T
9.
The Connection object's commit method saves any changes that have been made to the database. ANS: T
10.
When you create a table in an SQLite database, the RowID column is not automatically created. ANS: F
MULTIPLE CHOICE 1.
Which of the following do most developers prefer to use when developing applications that work with an intensive amount of data? a. text files b. binary files
c. d. ANS:
a database management system pickled objects C
2.
The standard language for working with database management systems is __________. a. SQL b. BASIC c. ADA d. COBOL ANS: A
3.
SQL stands for __________. a. structured query language b. standard equivalent language c. semiconductor qualified language d. simple equation library ANS: A
4.
The data that is stored in a row of a database is divided into __________. a. sections b. tables c. bytes d. columns ANS: D
5.
This is a column that holds a unique value for each row and can be used to identify specific rows. a. ID column b. public key c. designator column d. primary key ANS: D
6.
What will happen if you try to store duplicate data in a primary key column? a. The column will be duplicated. b. An error will occur. c. The duplicate data will have concurrency issues. d. The primary key column will not display the duplicate data. ANS: B
7.
What type of object does the sqlite3.connect function return? a. Cursor b. Database c. File d. Connection ANS: A
8.
In SQLite, you use the Cursor object’s ______________ method to pass an SQL statement to the DBMS.
a. commit b. execute c. dbms_pass d. run_sql ANS: B 9.
The __________ type of SQL statement is used to retrieve the rows from a table. a. GET b. SELECT c. READ d. RETRIEVE ANS: B
10.
This clause allows you to specify search criteria with the SELECT statement. a. SEARCH b. CRITERIA c. AS d. WHERE ANS: D
11.
The __________ SQL operator can be used to perform a search for a substring. a. STR b. LIKE c. WHERE d. SUB ANS: B
12.
To sort the results of a SQL query, you can use the __________ clause. a. SORT BY b. ALIGN ROW c. ORDER BY d. ASCEND ANS: C
13.
The __________ statement is used in SQL to insert a new row into a table, a. UPDATE b. ADD c. NEW d. INSERT ANS: D
14.
In SQL, the __________ statement is used to change the contents of an existing row in a table. a. SET ROW b. CHANGE c. UPDATE d. REFRESH ANS: C
15.
In SQL, the __________ statement is used to delete one or more rows from a table. a. DELETE b. DROP ROW c. REMOVE d. PURGE ANS: A
16.
In SQL, the __________ statement can be used to create a database table. a. NEW TABLE b. MAKE TABLE c. BUILD TABLE d. CREATE TABLE ANS: D
17.
In SQL, the __________ statement is used to delete a table from a database. a. REMOVE TABLE b. DEL TABLE c. DROP TABLE d. ERASE TABLE ANS: C
18.
This Cursor method returns the entire results of the previously executed SELECT statement, as a list of tuples. a. get_results b. getall c. fetchone d. fetchall ANS: D
19.
This Cursor method returns only one row of the results of the previously executed SELECT statement, as a tuple. a. get_results b. getall c. fetchone d. fetchall ANS: C
20.
Suppose an SQLite database has a table named Users. The Users table has an INTEGER column named Logins. Which SQL statement returns the average of the Logins column? a. SELECT AVG(Users) FROM Logins b. SELECT AVG(Logins) FROM Users c. SELECT AVERAGE(Logins) FROM Users d. SELECT Users.AVG(Logins) ANS: B
21.
Suppose an SQLite database has a table named Customers. The Customers table has a REAL column named Purchases. Which SQL statement returns the sum of the Purchases column? a. SELECT TOTAL(Customers) FROM Purchases
b. SELECT Customers.SUM(Purchases) c. SELECT COUNT(Purchases) FROM Customers d. SELECT SUM(Purchases) FROM Customers ANS: D 22.
If you want to know the number of rows in a table, or the number of rows that match a search criterion, you would use this SQL function. a. COUNT b. NUM_ROWS c. QUANTITY d. TOTAL ANS: A
23.
A column in one table that references a primary key in another table is known as a __________. a. secondary key b. foreign key c. referential key d. meta key ANS: B
24.
A qualified column name takes the form __________. a. ColumnName.TableName b. TableName.ColumnName c. RowName.TableName d. DatabaseURL.ColumnName ANS: B
25.
In SQLite, this type of exception is thrown any time a database error occurs. a. DBException b. DataError c. SQLException d. Error ANS: D