Debugging and Bug Hunting Quiz Quiz

  1. Identifying a Syntax Error

    Given the following line of Python code, what is the bug?nnprint('Debug this, world!')

    1. There is no bug; the code runs correctly.
    2. Misused quotes around string.
    3. Missing colon at end of line.
    4. print statemant is outdated.
    5. Indentation error detected.
  2. Uncaught Exception

    What is the main issue in this code snippet?nntry:n num = int('xyz')nexcept ZeroDivisionError:n print('Division by zero!')

    1. The except block catches the wrong exception type.
    2. 'int' can only convert numbers, not strings.
    3. There is an infinite loop missing.
    4. A semicolon is missing at the end of lines.
    5. Block should use catch instead of except.
  3. Type Error in JavaScript

    Where’s the bug in this JavaScript code?nnlet x = '10';nlet y = 2;nconsole.log(x * y);

    1. No actual bug, but type coercion occurs.
    2. It produces a SyntaxError.
    3. Variables x and y cannot be declared with let.
    4. String concatenation will occur instead of multiplication.
    5. console.lg should be used instead of console.log.
  4. 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}

    1. Off-by-one error: The loop sums one extra value.
    2. Variables are not initialized properly.
    3. Missing curly braces.
    4. The loop increments incorrectly.
    5. Typo in the variable 'sum'.
  5. Logical Bug

    Which type of bug does this code contain?nnif (isRaining = true) {n bringUmbrella();n}

    1. Assignment used instead of comparison operator.
    2. Function call is misspeled.
    3. The if statement is missing parentheses.
    4. There is a missing return statement.
    5. Logical operators are reversed.
  6. Null Reference Error

    What bug would cause this Java application to throw an exception?nnString str = null;nSystem.out.println(str.length());

    1. str is null, causing a NullPointerException.
    2. System.out.printIn is incorrect.
    3. The semicolon should be a colon.
    4. str should be initialized with a value.
    5. length should be len.
  7. Infinite Loop Detection

    Identify the bug in the following code:nnwhile (n u003E 0) {n n++;n}

    1. n is incremented instead of decremented, causing an infinite loop.
    2. Missing variable declaration for n.
    3. Condition will always be false.
    4. Brackets used incorrectly.
    5. while should be replaced with for.
  8. 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}

    1. Variable x is not defined in the console.log scope.
    2. console.log should be console.print.
    3. let should be replaced by var.
    4. 5 is not a valid value for x.
    5. Missing return value for foo().
  9. Index Out of Range

    What bug exists in this Python code?nnitems = [10, 20, 30]nprint(items[3])

    1. Attempting to access a list index out of range.
    2. items is not initialized properly.
    3. print is misspeled.
    4. list indexing should start at 1.
    5. Square brackets should be parentheses.
  10. 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}

    1. Variable value is redeclared in an inner scope, causing shadowing.
    2. System.out.println should be System.console.
    3. 8 is not a valid integer.
    4. if statement must have a condition.
    5. value variable must be declared outside the if block.