Bird
Raised Fist0
HLDsystem_design~10 mins

Shopping cart and session management in HLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify the unique session for a user.

HLD
session_id = request.cookies.get([1])
Drag options to blanks, or click blank then click option'
Acart_id
Buser_id
Csession_id
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user_id' instead of 'session_id' as cookie name.
Confusing 'cart_id' with session identifier.
2fill in blank
medium

Complete the code to add an item to the shopping cart stored in session.

HLD
session['cart'].[1](item_id)
Drag options to blanks, or click blank then click option'
Aappend
Bremove
Cclear
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which deletes an item instead of adding.
Using 'pop' which removes the last item.
3fill in blank
hard

Fix the error in the code to retrieve the cart items safely from session.

HLD
cart_items = session.get([1], [])
Drag options to blanks, or click blank then click option'
Acart
Bsession_id
Cuser_id
Ditems
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user_id' or 'session_id' which are unrelated keys for cart items.
Using 'items' which is not the standard key.
4fill in blank
hard

Fill both blanks to create a dictionary of item counts in the cart.

HLD
item_counts = {item: cart.count([1]) for item in set(cart) if cart.count(item) [2] 1}
Drag options to blanks, or click blank then click option'
Aitem
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators like '==' or '<' instead of '>'.
Passing wrong argument to count method.
5fill in blank
hard

Fill all three blanks to update the session cart and set cookie expiration.

HLD
session[[1]] = updated_cart
response.set_cookie([2], session[[3]], max_age=3600)
Drag options to blanks, or click blank then click option'
A'cart'
B'session_id'
D'user_id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user_id' as cookie name instead of 'session_id'.
Mixing keys between session and cookie.