Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a basic emergency handler function.
LLD
def handle_emergency(event): if event == [1]: print("Alert: Fire detected!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect event strings like 'Fire' (case sensitive)
Using unrelated events like 'flood' or 'earthquake'
✗ Incorrect
The emergency handler should detect a fire event, so the correct event string is "fire".
2fill in blank
mediumComplete the code to raise an alert when an emergency is detected.
LLD
def raise_alert(level): if level >= [1]: print("Emergency alert raised!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the threshold too high like 10, missing moderate emergencies
Setting the threshold too low like 1, causing false alerts
✗ Incorrect
The alert should be raised for emergencies with level 3 or higher, so the threshold is 3.
3fill in blank
hardFix the error in the emergency response function to correctly handle unknown events.
LLD
def emergency_response(event): match event: case "fire": print("Activate sprinklers") case "flood": print("Evacuate area") case _: print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes causing syntax errors
Using incomplete or incorrect messages
✗ Incorrect
The print statement requires a string literal, so the message must be enclosed in quotes.
4fill in blank
hardFill both blanks to create a dictionary mapping emergency types to their response actions.
LLD
emergency_actions = {
[1]: "Call fire department",
[2]: "Shut off electricity"
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string keys
Mixing up emergency types and response actions
✗ Incorrect
The dictionary keys should be emergency types as strings: "fire" and "power_outage".
5fill in blank
hardFill all three blanks to implement a function that logs emergency events with their severity and timestamp.
LLD
def log_emergency(event, severity): from datetime import datetime log_entry = { [1]: event, [2]: severity, [3]: datetime.now().isoformat() } print(log_entry)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent or unclear key names
Using variable names instead of string keys
✗ Incorrect
The dictionary keys should be descriptive strings: "event_type", "severity_level", and "timestamp".
