Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define an event in the event store.
Microservices
event = {"type": "UserCreated", "data": [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or string instead of a dictionary for event data.
✗ Incorrect
The event data should be a dictionary containing relevant details, like userId and name.
2fill in blank
mediumComplete the code to append an event to the event store.
Microservices
event_store.append([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Appending only event type or event data instead of the full event.
✗ Incorrect
We append the whole event object to the event store, not just its type or data.
3fill in blank
hardFix the error in the code to read events from the event store.
Microservices
for [1] in event_store: print(event)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name in the loop and print statement.
✗ Incorrect
The loop variable should be 'event' to match the print statement.
4fill in blank
hardFill both blanks to filter events of type 'OrderPlaced' from the event store.
Microservices
filtered_events = [event for event in event_store if event[1] [2] 'OrderPlaced']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' or accessing wrong attribute.
✗ Incorrect
We access the event's type attribute and check if it equals 'OrderPlaced'.
5fill in blank
hardFill all three blanks to create a dictionary of event counts by type.
Microservices
event_counts = [1](event.type for event in event_store if event.type[2] [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' for filtering, or missing Counter import.
✗ Incorrect
We use Counter to count event types, filtering out 'UserDeleted' events.