Identifying a Syntax Error
Given the following line of Python code, what is the bug?nnprint('Debug this, world!')
- There is no bug; the code runs correctly.
- Misused quotes around string.
- Missing colon at end of line.
- print statemant is outdated.
- Indentation error detected.
Uncaught Exception
What is the main issue in this code snippet?nntry:n num = int('xyz')nexcept ZeroDivisionError:n print('Division by zero!')
- The except block catches the wrong exception type.
- 'int' can only convert numbers, not strings.
- There is an infinite loop missing.
- A semicolon is missing at the end of lines.
- Block should use catch instead of except.
Type Error in JavaScript
Where’s the bug in this JavaScript code?nnlet x = '10';nlet y = 2;nconsole.log(x * y);
- No actual bug, but type coercion occurs.
- It produces a SyntaxError.
- Variables x and y cannot be declared with let.
- String concatenation will occur instead of multiplication.
- console.lg should be used instead of console.log.
Off-by-One Error
What kind of bug is found in this code scenario?nnfor (int i = 0; i u003C= 10; i++) {n sum += i;n}
- Off-by-one error: The loop sums one extra value.
- Variables are not initialized properly.
- Missing curly braces.
- The loop increments incorrectly.
- Typo in the variable 'sum'.
Logical Bug
Which type of bug does this code contain?nnif (isRaining = true) {n bringUmbrella();n}
- Assignment used instead of comparison operator.
- Function call is misspeled.
- The if statement is missing parentheses.
- There is a missing return statement.
- Logical operators are reversed.
Null Reference Error
What bug would cause this Java application to throw an exception?nnString str = null;nSystem.out.println(str.length());
- str is null, causing a NullPointerException.
- System.out.printIn is incorrect.
- The semicolon should be a colon.
- str should be initialized with a value.
- length should be len.
Infinite Loop Detection
Identify the bug in the following code:nnwhile (n u003E 0) {n n++;n}
- n is incremented instead of decremented, causing an infinite loop.
- Missing variable declaration for n.
- Condition will always be false.
- Brackets used incorrectly.
- while should be replaced with for.
Scope Issue
In this code, what bug might you encounter?nnfunction foo() {n if (true) {n let x = 5;n }n console.log(x);n}
- Variable x is not defined in the console.log scope.
- console.log should be console.print.
- let should be replaced by var.
- 5 is not a valid value for x.
- Missing return value for foo().
Index Out of Range
What bug exists in this Python code?nnitems = [10, 20, 30]nprint(items[3])
- Attempting to access a list index out of range.
- items is not initialized properly.
- print is misspeled.
- list indexing should start at 1.
- Square brackets should be parentheses.
Variable Shadowing
What is the issue with the following code?nnint value = 7;nif (true) {n int value = 8;n System.out.println(value);n}
- Variable value is redeclared in an inner scope, causing shadowing.
- System.out.println should be System.console.
- 8 is not a valid integer.
- if statement must have a condition.
- value variable must be declared outside the if block.