Bird
0
0

A developer wrote this code snippet to delete a book:

medium📝 Analysis Q6 of 15
LLD - Design — Library Management System
A developer wrote this code snippet to delete a book:
if book_id:
    delete book
return 'Deleted'

What is the main issue with this code?
AIt deletes the book even if book_id does not exist
BIt returns 'Deleted' even if no book was deleted
CIt returns nothing if book_id is missing
DIt uses wrong syntax for deletion
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the condition and return

    The code checks if book_id is truthy, deletes book, then returns 'Deleted' regardless.
  2. Step 2: Identify the problem

    If book_id is false or book does not exist, it still returns 'Deleted' which is misleading.
  3. Final Answer:

    It returns 'Deleted' even if no book was deleted -> Option B
  4. Quick Check:

    Return message must reflect actual deletion [OK]
Quick Trick: Return after deletion must confirm success [OK]
Common Mistakes:
MISTAKES
  • Ignoring return outside if
  • Assuming delete always succeeds
  • Not checking book existence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes