セクション 4. 章 8
single
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.
タスク
スワイプしてコーディングを開始
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.
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 4. 章 8
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください