0
0
DSA Pythonprogramming~30 mins

Array Traversal Patterns in DSA Python - Build from Scratch

Choose your learning style9 modes available
Array Traversal Patterns
📖 Scenario: You are working on a simple inventory system for a small bookstore. The store keeps a list of book titles and their prices. You want to practice going through this list to find books that meet certain price conditions.
🎯 Goal: Build a program that creates a list of book prices, sets a price limit, finds all books cheaper than or equal to that limit, and prints those prices.
📋 What You'll Learn
Create a list called book_prices with the exact values: 12.99, 7.50, 15.20, 5.99, 9.99
Create a variable called price_limit and set it to 10.00
Use a for loop with the variable price to traverse book_prices and collect prices less than or equal to price_limit into a list called affordable_books
Print the affordable_books list
💡 Why This Matters
🌍 Real World
Filtering items based on conditions is common in shopping apps, inventory systems, and data analysis.
💼 Career
Understanding how to traverse arrays and apply conditions is a fundamental skill for software developers and data analysts.
Progress0 / 4 steps
1
Create the list of book prices
Create a list called book_prices with these exact values: 12.99, 7.50, 15.20, 5.99, 9.99
DSA Python
Hint

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

2
Set the price limit
Create a variable called price_limit and set it to 10.00
DSA Python
Hint

Use the assignment operator = to set the value.

3
Find affordable books using a for loop
Use a for loop with the variable price to traverse book_prices and collect prices less than or equal to price_limit into a list called affordable_books
DSA Python
Hint

Start with an empty list. Use for price in book_prices: to go through each price. Use if price <= price_limit: to check the condition. Use append() to add to the list.

4
Print the affordable books list
Print the affordable_books list
DSA Python
Hint

Use print(affordable_books) to show the list.