Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Tuple Operations | Other Data Types
Introduction to Python
セクション 4.  8
single

single

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.

タスク

スワイプしてコーディングを開始

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.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 4.  8
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt