Bird
0
0

Identify the error in this state transition function:

medium📝 Analysis Q6 of 15
LLD - Design — Food Delivery System
Identify the error in this state transition function:
def transition(state, event):
    if state == 'placed' and event == 'ship'
        return 'shipped'
    return state
AUsing '==' instead of '=' in condition
BUsing 'return' inside if block
CIncorrect indentation of return statement
DMissing colon ':' after the if condition
Step-by-Step Solution
Solution:
  1. Step 1: Check Python syntax for if statements

    Python requires a colon ':' at the end of the if condition line.
  2. Step 2: Identify the missing colon

    The code misses ':' after 'if state == 'placed' and event == 'ship'' causing syntax error.
  3. Final Answer:

    Missing colon ':' after the if condition -> Option D
  4. Quick Check:

    Python if statement needs ':' [OK]
Quick Trick: Always add ':' after if conditions in Python [OK]
Common Mistakes:
  • Confusing '=' and '=='
  • Misplacing indentation
  • Thinking return inside if is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes