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
Manage a tuple representing a shelf of fruits by performing operations to count, find, and check stock levels.
-
Count how many times
"apples"appear in theshelftuple. Store this inapple_countand print:"Number of Apples: <$apple_count>". -
Find the index of the first occurrence of
"bananas"in theshelftuple. Store the index inbanana_indexand print:"First Banana Index: <$banana_index>". -
Check if the number of apples is less than 5. If true, print:
"Apples need to be restocked."Otherwise, print:"Apples are sufficiently stocked." -
Count how many times
"grapes"appear in theshelftuple. If grapes appear only once, print:"Grapes need to be restocked."Otherwise, print:"Grapes are sufficiently stocked." -
Check if
"oranges"exist in theshelftuple. If they do, print their index with:"Oranges are at index: <$orange_index>". If they don't exist, print:"Oranges are out of stock."
Output Requirements
- Print the number of apples:
"Number of Apples: <$apple_count>". - Print the index of the first occurrence of bananas:
"First Banana Index: <$banana_index>". - Print a message about the apple stock status:
"Apples need to be restocked."or"Apples are sufficiently stocked." - Print a message about the grape stock status:
"Grapes need to be restocked."or"Grapes are sufficiently stocked." - Print the index of oranges if they exist:
"Oranges are at index: <$orange_index>", or"Oranges are out of stock."
Note
You can use the
inandnot inoperators with both tuples and lists.
Requirements checklist
- Check that the value of
apple_countis equal to the number of times "apples" appears in theshelftuple. - Check that the value of
banana_indexis equal to the index of the first occurrence of "bananas" in theshelftuple. - If
apple_countis less than 5, check that the output includes "Apples need to be restocked." Otherwise, check that it includes "Apples are sufficiently stocked." - Check that the output includes "Grapes need to be restocked." if the count of "grapes" in
shelfis 1, otherwise check that it includes "Grapes are sufficiently stocked." - If "oranges" is in
shelf, check that the output includes "Oranges are at index: <$orange_index>", where<$orange_index>is the index of "oranges" inshelf. If not, check that it includes "Oranges are out of stock." - Check that the output includes "Number of Apples: <$apple_count>", where
<$apple_count>is the value from check 1. - Check that the output includes "First Banana Index: <$banana_index>", where
<$banana_index>is the value from check 2.
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 2.17
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
Manage a tuple representing a shelf of fruits by performing operations to count, find, and check stock levels.
-
Count how many times
"apples"appear in theshelftuple. Store this inapple_countand print:"Number of Apples: <$apple_count>". -
Find the index of the first occurrence of
"bananas"in theshelftuple. Store the index inbanana_indexand print:"First Banana Index: <$banana_index>". -
Check if the number of apples is less than 5. If true, print:
"Apples need to be restocked."Otherwise, print:"Apples are sufficiently stocked." -
Count how many times
"grapes"appear in theshelftuple. If grapes appear only once, print:"Grapes need to be restocked."Otherwise, print:"Grapes are sufficiently stocked." -
Check if
"oranges"exist in theshelftuple. If they do, print their index with:"Oranges are at index: <$orange_index>". If they don't exist, print:"Oranges are out of stock."
Output Requirements
- Print the number of apples:
"Number of Apples: <$apple_count>". - Print the index of the first occurrence of bananas:
"First Banana Index: <$banana_index>". - Print a message about the apple stock status:
"Apples need to be restocked."or"Apples are sufficiently stocked." - Print a message about the grape stock status:
"Grapes need to be restocked."or"Grapes are sufficiently stocked." - Print the index of oranges if they exist:
"Oranges are at index: <$orange_index>", or"Oranges are out of stock."
Note
You can use the
inandnot inoperators with both tuples and lists.
Requirements checklist
- Check that the value of
apple_countis equal to the number of times "apples" appears in theshelftuple. - Check that the value of
banana_indexis equal to the index of the first occurrence of "bananas" in theshelftuple. - If
apple_countis less than 5, check that the output includes "Apples need to be restocked." Otherwise, check that it includes "Apples are sufficiently stocked." - Check that the output includes "Grapes need to be restocked." if the count of "grapes" in
shelfis 1, otherwise check that it includes "Grapes are sufficiently stocked." - If "oranges" is in
shelf, check that the output includes "Oranges are at index: <$orange_index>", where<$orange_index>is the index of "oranges" inshelf. If not, check that it includes "Oranges are out of stock." - Check that the output includes "Number of Apples: <$apple_count>", where
<$apple_count>is the value from check 1. - Check that the output includes "First Banana Index: <$banana_index>", where
<$banana_index>is the value from check 2.
Solution
Thanks for your feedback!
single