QuestionQ19

VerifiedPython Basics for Data Analysis

You are creating a function to validate battery-voltage readings. The rules are:

  • If the reading is "MISSING" or None, return "Missing".
  • If the value is less than 2.5 or greater than 4.2, return "Outlier".
  • Otherwise, return "Normal".

Which version correctly implements this logic with the most robust conditional and nested structures? Select the best answer.

Explanation

Missing markers must be handled before evaluating numeric thresholds, preventing comparisons between None or a string and numbers. An outlier condition must use or because either a value below 2.5 or a value above 4.2 is outside the valid range. The nested branches in choice B return the required result for every case.

Community Discussion

No comments yet. Be the first to start the discussion!