Challenge: 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.
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 inshelf. Store this inapple_countand print:Number of Apples: <apple_count>. - Find the index of the first
"bananas"inshelf. Store this inbanana_indexand 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 inshelf. If grapes appear only once, print:Grapes need to be restocked.Otherwise, print:Grapes are sufficiently stocked. - If
"oranges"are inshelf, 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
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 1.89
Challenge: 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.
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 inshelf. Store this inapple_countand print:Number of Apples: <apple_count>. - Find the index of the first
"bananas"inshelf. Store this inbanana_indexand 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 inshelf. If grapes appear only once, print:Grapes need to be restocked.Otherwise, print:Grapes are sufficiently stocked. - If
"oranges"are inshelf, 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
Thanks for your feedback!
single