NEW
Font size
WorksheetsCh. 7 Exam Review
Total questions: 20
Worksheet time: 10mins
Which of the following is NOT a general category of error?
Sneaky Error
Syntax error
Logical error
Runtime exception
What general term to software engineers use to describe errors in programs?
Flops
Breakpoints
Tracepoints
Bugs
Which of the following is NOT displayed in a syntax error message?
The file name where the error was found
The suggested best practice for avoiding the error in the future
The line of code where the error was found
A carat (^) pointing at the likely location of the error within a statement
When you get a syntax error, what should you do if you can't find the problem at the line of code where the carat is pointing?
Look backwards (upwards) at earlier statements to see where the problem starts
Look downwards (forwards) at later statements to see where the problem ends
Engage the debugger and set a breakpoint
Call the Python support hotline
If a program runs without any error messages, but doesn't do what you want it to do, what kind of error do you likely have in your code?
Logical error
Syntax error
Runtime exception
Any of these is possible
When do you normally see the effects of a logical error?
When the program is running
Before the program starts
After the program ends
Any of these times is possible
What happens when a runtime exception is encountered?
Your program continues to run but may not behave the way you wanted
Your program hangs forever without any more input or output
Your program halts completely with an error message
An automatic error report is sent to the Python Software Foundation
Why are logical errors sometimes harder to find and fix?
You do not see any error messages that give you hints about the problem
The logical error messages are more complicated than other error messages
You have to keep re-starting your program after it crashes
You don't have any tools to help you find and fix those kinds of problems
When conducting a code review, in what order should you normally examine your statements?
From top to bottom, in the order they normally execute
From bottom to top, working backwards
Start with the longest and most complex statements first
Start with the shortest and easiest statements first
When Python runs a particular statement, which of the following will influence the behavior and success of that statement?
Earlier statements that have already run to create or update variable values
The comments you have left in the code for that statement
The statements that will run afterwards to provide more information
All of these are true
Which of the following statements is true about a code review?
Code reviews will not work if you don't import the debugger firsts
You should always start at the very beginning, no matter how many statements you have or where you think the problem lies
Code review is by far the slowest way to find and fix problems
You may be able to skip to a suspicious area of code if you think you know where the problem lies
What is wrong with the following code? age = int( input( How old are you? ) )
Nothing is wrong; the statement will run successfully
It will throw an exception at runtime due to the nested function calls
It does not correctly assign the result value to the variable
It is missing double quotes around the input() string parameter
If you want to print "Password verified" when the user guesses the matching password, what is wrong with the following code? password = "SECRET" guess = input("What's the password? ") if (guess != password): print("Password verified") else: print("Access denied")
It will print the opposite of what you want due to a logical error
It will show a syntax error
It will throw a runtime exception
Nothing is wrong; it will do exactly what you want
Where might you want to place program trace statements to help you understand your program?
Inside an "if" body to show when that logical path is taken
Before a long calculation to show all of the initial variable values
After a long calculation to show the results of the mathematical expression
All of these are good places
Which function do we suggest using to create your program trace statements?
trace()
print()
breakpoint()
display()
In what state is your program if it is executing at full speed and you can't observe your variables and lines of code in the debugger?
Break state
Running state
Hyper state
Unknown state
What do you need to do to enable the Python debugger for your program?
Nothing; the debugger is always available by default
Call pdb.load() to load the "pdb" library
Call pdb.set_trace() to load the "pdb" library
import the "pdb" library
Which of the following statements successfully sets a breakpoint for the Python debugger?
pdb.set_trace()
pdb.breakpoint()
pdb.stop()
print("Breaking here")
Which Python debugger command would you use to run the next line of code and then return to the break state?
continue (c)
step (s)
list (l)
prompt (p)
What Python debugger command will show you several lines of code around the line that is about to be executed?
display (d)
print (p)
status (s)
list (l)
