Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: List Management | Other Data Types
Introduction to Python (generated task tests)

bookChallenge: 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.

Task

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.

  1. Initialize Lists:

    • Create a list meat with the values: "Ham", 3.99, 50, "Sliced";
    • Create a list cheese with the values: "Cheddar", 5.49, 100, "Sharp";
    • Create a list condiment with the values: "Mustard", 1.99, 75, "Spicy".
  2. Create Main List:

    • Combine meat, cheese, and condiment lists into a single list called deli_dept.
  3. Restock Item:

    • If "Ham" is in the meat list and its quantity is less than 100, update its quantity to 100.
  4. Add Seasonal Meat:

    • Create a list seasonal_meat with the values: "Turkey", 4.50, 100, "Sliced";
    • Append seasonal_meat to deli_dept.
  5. Remove Condiment:

    • Remove the condiment list from deli_dept.
  6. Sort List:

    • Sort deli_dept alphabetically based on the first element of each sublist.

Output Requirements

  • Print the initial state of deli_dept with the message: "Initial Deli List: <$deli_dept>".
  • After all operations, print the updated state of deli_dept with 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

  1. Check that the variable meat is a list with values: "Ham", 3.99, 100, "Sliced" (the quantity must be 100 after restocking).
  2. Check that the variable cheese is a list with values: "Cheddar", 5.49, 100, "Sharp".
  3. Check that the variable condiment is a list with values: "Mustard", 1.99, 75, "Spicy".
  4. Check that the variable seasonal_meat is a list with values: "Turkey", 4.50, 100, "Sliced".
  5. Check that the variable deli_dept is a list containing only the lists for cheese, meat, and seasonal_meat, in alphabetical order by their first element.
  6. Check that the initial print output contains the string "Initial Deli List:" followed by a list containing meat, cheese, and condiment (in any order).
  7. Check that the final print output contains the string "Updated Deli List:" followed by a list containing only cheese, meat, and seasonal_meat (in alphabetical order by their first element).

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: 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.

Task

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.

  1. Initialize Lists:

    • Create a list meat with the values: "Ham", 3.99, 50, "Sliced";
    • Create a list cheese with the values: "Cheddar", 5.49, 100, "Sharp";
    • Create a list condiment with the values: "Mustard", 1.99, 75, "Spicy".
  2. Create Main List:

    • Combine meat, cheese, and condiment lists into a single list called deli_dept.
  3. Restock Item:

    • If "Ham" is in the meat list and its quantity is less than 100, update its quantity to 100.
  4. Add Seasonal Meat:

    • Create a list seasonal_meat with the values: "Turkey", 4.50, 100, "Sliced";
    • Append seasonal_meat to deli_dept.
  5. Remove Condiment:

    • Remove the condiment list from deli_dept.
  6. Sort List:

    • Sort deli_dept alphabetically based on the first element of each sublist.

Output Requirements

  • Print the initial state of deli_dept with the message: "Initial Deli List: <$deli_dept>".
  • After all operations, print the updated state of deli_dept with 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

  1. Check that the variable meat is a list with values: "Ham", 3.99, 100, "Sliced" (the quantity must be 100 after restocking).
  2. Check that the variable cheese is a list with values: "Cheddar", 5.49, 100, "Sharp".
  3. Check that the variable condiment is a list with values: "Mustard", 1.99, 75, "Spicy".
  4. Check that the variable seasonal_meat is a list with values: "Turkey", 4.50, 100, "Sliced".
  5. Check that the variable deli_dept is a list containing only the lists for cheese, meat, and seasonal_meat, in alphabetical order by their first element.
  6. Check that the initial print output contains the string "Initial Deli List:" followed by a list containing meat, cheese, and condiment (in any order).
  7. Check that the final print output contains the string "Updated Deli List:" followed by a list containing only cheese, meat, and seasonal_meat (in alphabetical order by their first element).

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3
single

single

some-alt