Challenge: List Management
Are you ready to apply your new knowledge of lists and list methods in a practical setting?
This challenge will engage you in managing a grocery store's deli department items, requiring you to utilize nested lists, list methods, and conditional logic.
Swipe to start coding
Manage a list of deli items by initializing, updating, and organizing them across different categories such as meats, cheeses, and condiments.
-
Initialize Lists:
- Create a list
meatwith the values:"Ham",3.99,50,"Sliced"; - Create a list
cheesewith the values:"Cheddar",5.49,100,"Sharp"; - Create a list
condimentwith the values:"Mustard",1.99,75,"Spicy".
- Create a list
-
Create Main List:
- Combine
meat,cheese, andcondimentlists into a single list calleddeli_dept.
- Combine
-
Restock Item:
- If
"Ham"is in themeatlist and its quantity is less than100, update its quantity to100.
- If
-
Add Seasonal Meat:
- Create a list
seasonal_meatwith the values:"Turkey",4.50,100,"Sliced"; - Append
seasonal_meattodeli_dept.
- Create a list
-
Remove Condiment:
- Remove the
condimentlist fromdeli_dept.
- Remove the
-
Sort List:
- Sort
deli_deptalphabetically based on the first element of each sublist.
- Sort
Output Requirements
- Print the initial state of
deli_deptwith the message:"Initial Deli List: <$deli_dept>". - After all operations, print the updated state of
deli_deptwith the message:"Updated Deli List: <$deli_dept>".
Note
Sorting the list will be based on the first value of each sublist (e.g.,
"Ham","Cheddar","Turkey").
Requirements checklist
- Check that the variable
meatis a list with values: "Ham", 3.99, 100, "Sliced" (the quantity must be 100 after restocking). - Check that the variable
cheeseis a list with values: "Cheddar", 5.49, 100, "Sharp". - Check that the variable
condimentis a list with values: "Mustard", 1.99, 75, "Spicy". - Check that the variable
seasonal_meatis a list with values: "Turkey", 4.50, 100, "Sliced". - Check that the variable
deli_deptis a list containing only the lists forcheese,meat, andseasonal_meat, in alphabetical order by their first element. - Check that the initial print output contains the string "Initial Deli List:" followed by a list containing
meat,cheese, andcondiment(in any order). - Check that the final print output contains the string "Updated Deli List:" followed by a list containing only
cheese,meat, andseasonal_meat(in alphabetical order by their first element).
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
What are the specific requirements for the deli department items challenge?
Can you give me an example of how to use nested lists and list methods for this task?
What kind of conditional logic will I need to use in this challenge?
Awesome!
Completion rate improved to 2.17
Challenge: List Management
Swipe to show menu
Are you ready to apply your new knowledge of lists and list methods in a practical setting?
This challenge will engage you in managing a grocery store's deli department items, requiring you to utilize nested lists, list methods, and conditional logic.
Swipe to start coding
Manage a list of deli items by initializing, updating, and organizing them across different categories such as meats, cheeses, and condiments.
-
Initialize Lists:
- Create a list
meatwith the values:"Ham",3.99,50,"Sliced"; - Create a list
cheesewith the values:"Cheddar",5.49,100,"Sharp"; - Create a list
condimentwith the values:"Mustard",1.99,75,"Spicy".
- Create a list
-
Create Main List:
- Combine
meat,cheese, andcondimentlists into a single list calleddeli_dept.
- Combine
-
Restock Item:
- If
"Ham"is in themeatlist and its quantity is less than100, update its quantity to100.
- If
-
Add Seasonal Meat:
- Create a list
seasonal_meatwith the values:"Turkey",4.50,100,"Sliced"; - Append
seasonal_meattodeli_dept.
- Create a list
-
Remove Condiment:
- Remove the
condimentlist fromdeli_dept.
- Remove the
-
Sort List:
- Sort
deli_deptalphabetically based on the first element of each sublist.
- Sort
Output Requirements
- Print the initial state of
deli_deptwith the message:"Initial Deli List: <$deli_dept>". - After all operations, print the updated state of
deli_deptwith the message:"Updated Deli List: <$deli_dept>".
Note
Sorting the list will be based on the first value of each sublist (e.g.,
"Ham","Cheddar","Turkey").
Requirements checklist
- Check that the variable
meatis a list with values: "Ham", 3.99, 100, "Sliced" (the quantity must be 100 after restocking). - Check that the variable
cheeseis a list with values: "Cheddar", 5.49, 100, "Sharp". - Check that the variable
condimentis a list with values: "Mustard", 1.99, 75, "Spicy". - Check that the variable
seasonal_meatis a list with values: "Turkey", 4.50, 100, "Sliced". - Check that the variable
deli_deptis a list containing only the lists forcheese,meat, andseasonal_meat, in alphabetical order by their first element. - Check that the initial print output contains the string "Initial Deli List:" followed by a list containing
meat,cheese, andcondiment(in any order). - Check that the final print output contains the string "Updated Deli List:" followed by a list containing only
cheese,meat, andseasonal_meat(in alphabetical order by their first element).
Solution
Thanks for your feedback!
single