NEW
Font size
WorksheetsPython Unit 4 - Loops & Error Handling
Total questions: 34
Worksheet time: 17mins
Used to make a program repeat a series of instructions for either a certain number of times or until a condition is met.
loop
endless loop
if / else
circle
A loop that runs continuously or won't stop because the condition the loop is evaluating cannot be satisfied.
loop
endless loop
if / else
circle
Instruction in Python to create a loop that will run continuously when a condition is True. Looping ends when condition is False.
while
for
continue
endless loop
A type of loop in Python that is designed to work through the number of items in a list, a range, or characters of a string.
while
for
continue
endless loop
Python statement to redirect program execution in a loop back to the beginning of the loop rather than finishing the rest of the instructions contained in the loop.
while
for
continue
endless loop
Keystroke combination that usually terminates execution of Python programs by sending the “break” command to the Python shell.
Ctrl+c
break
fault
Ctrl+b
Python statement that will stop code executing within a loop & advance to the first statement after the end of the loop.
Ctrl+c
break
fault
Ctrl+b
A coding error or bug.
scapegoat
break
fault
An I.D. ten-T problem
Checking the user input to determine whether or not it is an acceptable value, can’t be used, or will trigger an error.
validation
exception
counter
idiot proofing
When Python encounters values or statements that cannot be processed. Program execution is halted & a description provided.
codus idiotus
exception
counter
speed bump
A variable that is used inside a loop that controls the number of iterations of the loop. Is typically incremented by 1 on each pass.
flag
exception
counter
incrementor
Code added to a program to handle exceptions by directing the program to statements that can control or correct the exception.
Error handlers
Exception handler
validation
fixer upper
A segment of code that will execute if a designated error or exception occurs.
Error handlers
Exception handler
range
terminator
Python keyword to indicate that if any of the statements in a block of code throw an exception, that execution should be routed to the exception handler for that EXACT specific error.
try:
else:
for
except
Keyword to begin an exception handler. When the specified error occurs, the code following this keyword will be executed.
try:
continue
for
except
Collection of objects (strings, integers, etc) that is ordered an cannot be changed. Values can be referenced using brackets [ ]
tuple
list
group
range
A Python function that contains 2 arguments. 1st number is lower limit to be used, 2nd is Exclusive Upper Limit which isn’t used.
tuple
list
group
range
Identify the keyword that should be placed in position R for this Error Handler to work.
except
False
try
while
Identify the keyword that should be placed in position S for this Error Handler to work.
except
False
try
while
Identify the keyword that should be placed in position T for this Error Handler to work.
except
False
try
while
Identify the keyword that should be placed in position U for this Error Handler to work.
except
False
try
while
You are developing a program for an online product distribution company. You need the program to iterate through a list of products and escape when a target product ID is found. How should you complete this code for the area labeled X ?
while
for
if
break
**You are developing a program for an online product distribution company. You need the program to iterate through a list of products and escape when a target product ID is found. How should you complete this code for the area labeled Y ?
while
for
if
break
You have written the code shown here.
What will be the value of result on the 1st iteration of this loop?
0
5
10
There is an exception in the code, it will not print a value.
You have written the code shown here.
What will be the value of count on the last iteration of this loop?
95
99
100
105
There is an fault in the code, it will not print a value.
You have written the code shown here.
What will be the value of result on the last iteration of this loop if you added the following line of code immediately after the line "result = ..."
if count == 4 : break
0
30
40
950
No value will be printed because that would create an exception in the code.
You want to print a list of the students in this tuple. Select the command that will print a list of the 7 names.
print(name)
print(students)
print(student)
print(students[counter])
None of these selections will work.
An ice cream store wants customers to order by number to streamline service. You're writing the program to do this.
Which Python function would you use to verify that when they enter an integer, that it is between 1 and 4?
while
if
try
for
An ice cream store wants customers to order by number to streamline service. You're writing the program to do this.
Which Python function would you use to keep your program from stopping if they don't input an integer?
while
if
try
for
An ice cream store wants customers to order by number to streamline service. You're writing the program to do this.
Which Python function would you use to keep prompting the customer until they enter an integer between 1 and 4?
while
if
try
for
An ice cream store wants to send a thank you letter to all of its' customers and wants you to make a listing of all their customers (maybe even with addresses if you know how).
Which Python function would you be using to generate a list of the customers?
while
try
for
endless loop
You have programmed a new robot, Joe2020, to carry no more than 25 dozen donuts from the Krispy Kreme truck to the Tech Lab.
You have no idea how many boxes might be in the truck so your loop is "for donuts in donut_truck :"
How can you get the Joe2020 to escape/exit the loop after carrying in 25 boxes of donuts?
if count == 25 : break
if count > 25 : break
if count <= 25 : break
if count => 25 : break
Wave a Krispy Kreme donut in front of Joe2020
A variable that is used inside a loop that control whether the loop should continue by changing from False to True or vise versa.
flag
exception
counter
incrementor
In Python, tuples are considered "immutable". What does that mean?
It cannot be changed or modified in any way.
You can add to the tuple, but not change any existing items.
It means that data is silent, and cannot be printed.
It means someone who won't shut up, kinda like some of the robots in Star Wars.
