Bird
0
0

In the following code snippet, what is the bug?

medium📝 Analysis Q7 of 15
LLD - Design — Library Management System
In the following code snippet, what is the bug?
if not book_id:
    delete book
    return 'Deleted'
else:
    return 'Book ID missing'
AIt returns 'Deleted' when book_id exists
BIt deletes book when book_id is missing
CIt deletes the book when book_id exists
DIt has syntax errors
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition logic

    Code deletes book if book_id is missing (not book_id is true).
  2. Step 2: Identify the bug

    Deleting without a valid book_id is wrong; logic is inverted.
  3. Final Answer:

    It deletes book when book_id is missing -> Option B
  4. Quick Check:

    Delete requires valid book_id [OK]
Quick Trick: Check condition logic carefully for negations [OK]
Common Mistakes:
MISTAKES
  • Confusing not operator
  • Deleting without ID
  • Misplaced return statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes