0
0
Pythonprogramming~15 mins

Searching and counting elements in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Counting Specific Items in a Fruit Basket
๐Ÿ“– Scenario: Imagine you have a basket full of different fruits. You want to find out how many apples are in the basket.
๐ŸŽฏ Goal: You will write a program that counts how many times the fruit 'apple' appears in a list of fruits.
๐Ÿ“‹ What You'll Learn
Create a list called fruits with specific fruit names
Create a variable called target_fruit to hold the fruit name to count
Use a for loop to count how many times target_fruit appears in fruits
Print the count with a clear message
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Counting specific items in a list is useful in many real-life situations, like counting votes, inventory items, or survey answers.
๐Ÿ’ผ Career
This skill helps in data analysis, quality control, and any job that requires summarizing or searching through data.
Progress0 / 4 steps
1
Create the fruit list
Create a list called fruits with these exact items in order: 'apple', 'banana', 'apple', 'orange', 'apple', 'banana'
Python
Need a hint?

Use square brackets [] to create a list and separate items with commas.

2
Set the fruit to count
Create a variable called target_fruit and set it to the string 'apple'
Python
Need a hint?

Use an equals sign = to assign the string 'apple' to target_fruit.

3
Count how many times the target fruit appears
Create a variable called count and set it to 0. Then use a for loop with the variable fruit to go through each item in fruits. Inside the loop, if fruit is equal to target_fruit, add 1 to count.
Python
Need a hint?

Remember to start count at zero before the loop. Use for fruit in fruits: to check each fruit.

4
Print the count result
Write a print statement to display: "Number of apples: " followed by the value of count using an f-string.
Python
Need a hint?

Use print(f"Number of apples: {count}") to show the result clearly.