
Bugs & Debugging Topic Exercises - Part 3
Authored by Nguyễn Hoàng
Computers
10th Grade

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the issue with this for loop?
range(10) is not a valid function.
The print statement is not indented.
i must be defined before the loop.
The loop requires a step argument.
Answer explanation
This causes an IndentationError (a specific type of SyntaxError).
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of these statements about Syntax Errors is true?
The code will run halfway before stopping at the error.
They occur because of incorrect logic, not incorrect structure.
The Python interpreter cannot parse the code because it violates the language rules.
They only happen when you divide by zero.
Answer explanation
Syntax errors prevent the script from executing entirely.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the logic error in the following code intended to calculate the average of two numbers?
It will cause a SyntaxError.
It will cause a TypeError because you cannot divide integers.
Due to operator precedence, it divides num2 by 2 first, then adds num1.
The variable average is a reserved keyword.
Answer explanation
In Python, division (/) has higher operator precedence than addition (+). The code calculates 20 / 2 = 10 and then adds 10 + 10, resulting in 20.0. To fix this, you would need parentheses: (num1 + num2) / 2.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
A programmer wants to print numbers from 1 to 5. Why does this code fail logically?
It prints 1, 2, 3, 4, 5, 6.
It only prints 1, 2, 3, 4 because the stop value in range is exclusive.
It starts printing from 0.
The range function requires three arguments.
Answer explanation
The range(start, stop) function in Python is exclusive of the stop value. range(1, 5) generates numbers 1, 2, 3, and 4. To include 5, you must use range(1, 6).
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the logical flaw in this "Free Coffee" eligibility check?
(Requirement: Customer must be over 65 OR have a membership card.)
It uses == True which is not allowed.
It uses and instead of or, requiring the customer to meet both conditions.
It will print "Free coffee!" even if the age is 20.
There is no error; the code works perfectly for the requirement.
Answer explanation
The requirement states the customer needs the age OR the card. By using and, the code forces the customer to have both. Even if a customer is 90 years old, they won't get coffee if they forgot their card.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Why will the following loop become an "infinite loop" (a common logic error)?
The condition i < 10 is always false.
The increment i = i + 1 only happens when i is exactly 5; otherwise, i stays 1 forever.
Python does not support while loops.
The print statement must be outside the loop.
Answer explanation
The variable i starts at 1. The code says "if i is 5, add 1." But since i is 1, it never hits that if block, so i never changes. It stays 1 forever, and the loop never ends because 1 is always less than 10.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following best describes a "Logic Error"?
The code fails to run due to a missing colon.
The code crashes with a ZeroDivisionError.
The code runs to completion but gives an incorrect output.
The code uses a variable that hasn't been defined.
Answer explanation
A "Logic Error" occurs when the program's syntax is completely correct, and it executes without crashing, but it produces the wrong result because the underlying algorithm or math is flawed (e.g., using + instead of -).
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?