Reviewing AI-Generated Code Questions with Answers

28 practice questions on Reviewing AI-Generated Code (AI Tools for Developers) with answers and step-by-step solutions. Try 10 samples below, then practise all 28 free in the AptiNest app.

Sample questions

Question 1Easy

Which is the best first step when an AI suggests a package to install?

  1. Check that it exists and is well maintained
  2. Install every similarly named package so one of them works
  3. Ignore what it does
  4. Install it globally with sudo

Answer: A. Check that it exists and is well maintained

Explanation

Verifying the package protects you from hallucinated or malicious names.

Step-by-step solution

  1. Check that it exists and is well maintained.
  2. Verify its reputation to avoid fake packages.
  3. Ensure it's safe before proceeding with installation.

Why the other options are wrong

  • B. Installing similarly named packages hoping one works is risky and can pull in malicious packages.
  • C. Ignoring what the package does is unsafe; you must know its purpose before installing it.
  • D. Installing globally with sudo gives a package system-wide rights before it is checked, which is risky.

Tip: Check package sources and reviews before trusting AI suggestions.

Question 2Easy

Which is a good habit when accepting an AI code suggestion?

  1. Accept it only if it is longer than ten lines
  2. Read every line and make sure you can explain it
  3. Accept it with Tab as fast as possible
  4. Accept it if the variable names sound professional

Answer: B. Read every line and make sure you can explain it

Explanation

If you can't explain a line, you can't maintain or debug it; understanding comes before accepting.

Step-by-step solution

  1. Accepting a suggestion adds code you will have to maintain and debug.
  2. If you cannot explain a line, you cannot fix it later.
  3. So read every line and make sure you understand it before accepting.
  4. That habit is option B.

Why the other options are wrong

  • A. The length of a suggestion says nothing about whether it is right.
  • C. Accepting quickly skips the checks that catch mistakes.
  • D. Professional-sounding names do not show that the code is correct.

Tip: Understand a suggestion line by line before you press Tab.

Question 3Easy

Why is "it compiles" not enough evidence that AI-generated code is correct?

  1. Compiled code cannot have bugs, so this is a trick question
  2. Code can compile and still produce wrong results
  3. Compilers always reject AI-generated code
  4. Only interpreted code can be wrong

Answer: B. Code can compile and still produce wrong results

Explanation

Logic errors, wrong edge-case handling and security flaws all pass compilation.

Step-by-step solution

  1. Compiling means the code follows syntax rules.
  2. It does not check if logic is correct.
  3. So code can compile but still be wrong.

Why the other options are wrong

  • A. Compiled code can still have bugs; compiling only checks syntax and types, not whether the logic is right.
  • C. Compilers do not reject AI-generated code by default; they only reject code with syntax or type errors.
  • D. Interpreted code is not the only kind that can be wrong; compiled code can also give wrong results.

Tip: Always test code, not just compile it.

Question 4Easy

Who should understand AI-generated code before it is merged?

  1. The developer submitting it and the reviewer
  2. Only the end users who will report bugs
  3. Nobody, as long as tests exist
  4. Only the AI tool

Answer: A. The developer submitting it and the reviewer

Explanation

If no human understands the code, nobody can maintain or debug it; submitters should be able to explain every change.

Step-by-step solution

  1. Human understanding ensures code can be maintained and debugged.
  2. Submitters must explain their changes clearly.
  3. Reviewers need to check code quality and logic.
  4. End users may not know how the code works internally.
  5. AI tools cannot replace human judgment in code reviews.

Why the other options are wrong

  • B. End users do not need to understand the code before merge; the submitter and reviewer must.
  • C. Tests help but cannot replace understanding; merging code nobody understands is unsafe.
  • D. The AI tool cannot be accountable for merged code; people must understand and maintain it.

Tip: Always have humans review AI-generated code before merging.

Question 5Medium

Which review question is MOST useful for AI-generated error handling?

  1. "Is the indentation four spaces?"
  2. "What happens if this call fails or times out?"
  3. "Is the function name written in English and in snake_case?"
  4. "Could this be one line shorter?"

Answer: B. "What happens if this call fails or times out?"

Explanation

AI code often covers the happy path well and misses failure modes; asking about failures exposes gaps.

Step-by-step solution

  1. Error handling is about what happens when things go wrong.
  2. Asking what happens on failure or timeout checks real behaviour.
  3. Style questions do not test this.

Why the other options are wrong

  • A. Indentation is a style matter.
  • C. Naming is a style matter.
  • D. Shorter code is not safer.

Tip: Ask 'what if this fails?'

Question 6Medium

AI-generated Python:

nums = [1, 2, 3, 4]
for n in nums:
    if n % 2 == 0:
        nums.remove(n)
print(nums)

What is printed?

  1. [1, 2, 3, 4]
  2. [1, 3]
  3. An error about changing the list during iteration
  4. [2, 4]

Answer: B. [1, 3]

Explanation

Here removal happens to work, but mutating a list while iterating skips elements in general (try [2, 4]); building a new list is the safe pattern.

Step-by-step solution

  1. The loop visits the list by position while the list is changing.
  2. n=1 is odd, so nothing happens; n=2 is even, so it is removed and the list becomes [1, 3, 4].
  3. The loop moves on to position 2, which now holds 4; it is even, so it is removed and the list becomes [1, 3].
  4. The loop then stops because it is past the end; the printed result is [1, 3], option B.

Why the other options are wrong

  • A. The 2 and the 4 are even and are removed, so the list cannot stay unchanged.
  • C. Python does not raise an error here; the loop just skips an element.
  • D. The 3 is odd and is kept, so the result cannot be [2, 4].

Tip: Do not remove items from a list while looping over it; build a new list with a comprehension.

Question 7Medium

AI suggests catching every exception with except Exception: pass. Why is this a problem?

  1. It silently hides real errors, making bugs hard to find
  2. Python does not allow catching the base Exception class in any function
  3. It makes the program crash on every run
  4. It is required by PEP 8 and is therefore fine

Answer: A. It silently hides real errors, making bugs hard to find

Explanation

Swallowing all exceptions hides failures; catch specific exceptions and log or handle them deliberately.

Step-by-step solution

  1. 'except Exception: pass' swallows all errors.
  2. The program continues quietly while bugs hide.

Why the other options are wrong

  • B. Python allows catching Exception.
  • C. It does not crash, which is the issue.
  • D. PEP 8 does not require it.

Tip: Never swallow errors silently.

Question 8Medium

An AI-written function calls str.removeprefix() but your servers run Python 3.7. What kind of issue is this?

  1. Version-incompatible API usage
  2. A hallucinated package
  3. A prompt injection hidden inside the standard library documentation
  4. A licence violation

Answer: A. Version-incompatible API usage

Explanation

removeprefix was added in Python 3.9; AI may use APIs newer (or older) than your target environment.

Step-by-step solution

  1. str.removeprefix() is available from Python 3.9 onwards.
  2. Python 3.7 does not support this method.
  3. Using a feature not present in the server's Python version causes an error.
  4. This is a version-incompatible API usage issue.
  5. Final answer: A (Version-incompatible API usage).

Why the other options are wrong

  • B. A hallucinated package is an invented library name, not a real method that is too new for Python 3.7.
  • C. A prompt injection is hidden text that steers an AI, and standard library docs do not contain it here.
  • D. A licence violation concerns copyright terms for reusing code, not a method missing from an older Python.

Tip: Always check Python version compatibility before deploying code.

Question 9Hard

AI-generated JavaScript:

console.log(0.1 * 3 === 0.3, [] == false, "5" - 2);

What is logged?

  1. false false "52"
  2. true true 3
  3. false true 3
  4. true false 3

Answer: C. false true 3

Explanation

0.1*3 is 0.30000000000000004; [] coerces to "" then 0 which equals false; "5" - 2 converts to numbers giving 3.

Step-by-step solution

  1. 0.1 * 3 = 0.30000000000000004, so 0.1 * 3 === 0.3 is false.
  2. [] coerces to empty string then to 0, which equals false.
  3. "5" - 2 converts to numbers giving 5 - 2 = 3.
  4. Final result: false true 3.

Why the other options are wrong

  • A. [] == false is true, and "5" - 2 is numeric subtraction giving 3, not the string "52".
  • B. 0.1 * 3 === 0.3 is false due to floating point error, so the first value is not true.
  • D. The second value is true, not false, because [] loosely equals false after conversion.

Tip: Remember type coercion and floating-point quirks in JS.

Question 10Hard

Review this AI-generated helper:

def add_item(item, items=[]):
    items.append(item)
    return items

print(add_item(1))
print(add_item(2))

What does it print?

  1. [1, 2] then [1, 2]
  2. An error on the second call
  3. [1] then [1, 2]
  4. [1] then [2]

Answer: C. [1] then [1, 2]

Explanation

The default list is created once and shared between calls, a classic subtle bug; use items=None and create a new list inside.

Step-by-step solution

  1. The default value items=[] is created once, when the function is defined, and every call shares that same list.
  2. First call: append 1 to the shared list, so it holds [1] and prints [1].
  3. Second call: the same list now holds [1]; append 2, so it holds [1, 2] and prints [1, 2].
  4. So the output is [1] then [1, 2], which is option C.

Why the other options are wrong

  • A. The first call prints only [1], because the list is still empty before it is appended.
  • B. No error is raised; appending to a list is valid.
  • D. The second call does not start from an empty list, because the default list is shared.

Tip: Never use a mutable default like [] in Python; use items=None and create the list inside the function.

Practise all 28 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all AI Tools for Developers topics · All topics