0
0
Pythonprogramming~30 mins

Length and iteration methods in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Length and Iteration Methods
📖 Scenario: Imagine you are building a small program to manage a list of books in a digital library. You want to store book titles, count how many books there are, and display each book title one by one.
🎯 Goal: You will create a list of book titles, calculate the total number of books using len(), iterate through the list using a for loop, and print both the titles and the total count.
📋 What You'll Learn
Create a list called books with the given titles
Use the len() function to count the number of books
Use a for loop to iterate through the list
Print each book title and the total number of books
💡 Why This Matters
🌍 Real World
Managing lists of items, like books, products, or tasks, is common in many jobs and daily life.
💼 Career
Understanding how to count and loop through lists is a basic skill for programming jobs, data handling, and automation.
Progress0 / 4 steps
1
Create the list of books
Create a list called books with these exact titles: 'Python Basics', 'Data Science', 'Machine Learning', 'Deep Learning'
Python
Need a hint?

Use square brackets [] to create a list and separate each book title with commas.

2
Count the total books
Create a variable called total_books and set it to the length of the books list using the len() function
Python
Need a hint?

Use len(books) to find how many items are in the list.

3
Print each book title
Use a for loop with the variable book to iterate over the books list and print each book
Python
Need a hint?

Use for book in books: to loop through each book and print it inside the loop.

4
Print the total number of books
Print the value of the variable total_books to show how many books are in the list
Python
Need a hint?

Use print(total_books) after the loop to show the total count.