Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Tuple Operations | Other Data Types
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to Python

bookChallenge: Tuple Operations

Your grocery store's system is designed to track the inventory of items on different shelves using tuples, as tuples provide a way to ensure the data is immutable once set.

However, the store needs to monitor certain items and track their quantities or positions to assist in restocking or rearranging.

You are tasked with analyzing and managing inventory data using tuples to determine certain metrics and take actions based on specific criteria.

Task

Swipe to start coding

Work with the shelf tuple, which lists the fruits on a grocery shelf. Complete these steps:

  • Count how many times "apples" appear in shelf. Store this in apple_count and print: Number of Apples: <apple_count>.
  • Find the index of the first "bananas" in shelf. Store this in banana_index and print: First Banana Index: <banana_index>.
  • If there are fewer than 5 apples, print: Apples need to be restocked. Otherwise, print: Apples are sufficiently stocked.
  • Count how many times "grapes" appear in shelf. If grapes appear only once, print: Grapes need to be restocked. Otherwise, print: Grapes are sufficiently stocked.
  • If "oranges" are in shelf, print their index with: Oranges are at index: <orange_index>. If not, print: Oranges are out of stock.

Expected output:

  • The number of apples.
  • The index of the first bananas.
  • The apple stock status message.
  • The grape stock status message.
  • The oranges index or out of stock message.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 8
single

single

Ask AI

expand

Ask AI

ChatGPT

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

close

bookChallenge: Tuple Operations

Swipe to show menu

Your grocery store's system is designed to track the inventory of items on different shelves using tuples, as tuples provide a way to ensure the data is immutable once set.

However, the store needs to monitor certain items and track their quantities or positions to assist in restocking or rearranging.

You are tasked with analyzing and managing inventory data using tuples to determine certain metrics and take actions based on specific criteria.

Task

Swipe to start coding

Work with the shelf tuple, which lists the fruits on a grocery shelf. Complete these steps:

  • Count how many times "apples" appear in shelf. Store this in apple_count and print: Number of Apples: <apple_count>.
  • Find the index of the first "bananas" in shelf. Store this in banana_index and print: First Banana Index: <banana_index>.
  • If there are fewer than 5 apples, print: Apples need to be restocked. Otherwise, print: Apples are sufficiently stocked.
  • Count how many times "grapes" appear in shelf. If grapes appear only once, print: Grapes need to be restocked. Otherwise, print: Grapes are sufficiently stocked.
  • If "oranges" are in shelf, print their index with: Oranges are at index: <orange_index>. If not, print: Oranges are out of stock.

Expected output:

  • The number of apples.
  • The index of the first bananas.
  • The apple stock status message.
  • The grape stock status message.
  • The oranges index or out of stock message.

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Β 8
single

single

some-alt