# ============================================================
# HOMEWORK: Loop Mastery & Algorithm Foundations
# ============================================================
# Complete this after Lesson 6
# Focus on: Loop patterns and linear search
# ============================================================


# ============================================================
# PART 1: Loop Basics
# ============================================================

# --- TASK 1A: Countdown ---
# Print a countdown from 5 to 1, then "Liftoff!"
# Use range() with a negative step.
# Expected: 5, 4, 3, 2, 1, Liftoff!

# YOUR CODE HERE:



# --- TASK 1B: Iterate with Index ---
# Print each letter of "PYTHON" with its position (starting at 1).
# Use enumerate() with start=1.
# Expected:
# 1: P
# 2: Y
# ... etc

word = "PYTHON"

# YOUR CODE HERE:




# ============================================================
# PART 2: Loop Patterns
# ============================================================

numbers = [23, 67, 45, 89, 12, 56, 78, 34, 91, 43]


# --- TASK 2A: Counting ---
# Count how many numbers are greater than 50.

# YOUR CODE HERE:
# count = ?

# print(f"Numbers greater than 50: {count}")  # Should print 5



# --- TASK 2B: Accumulation ---
# Calculate the sum of all numbers, then the average.

# YOUR CODE HERE:
# total = ?
# average = ?

# print(f"Sum: {total}, Average: {average}")  # Sum: 538, Average: 53.8



# --- TASK 2C: Finding with Break ---
# Find the FIRST number divisible by 7. Stop as soon as you find it.

# YOUR CODE HERE:
# first_div_by_7 = ?

# print(f"First divisible by 7: {first_div_by_7}")  # Should print 56



# --- TASK 2D: Filtering ---
# Create a new list with only numbers less than 50.

# YOUR CODE HERE:
# small_numbers = ?

# print(f"Small numbers: {small_numbers}")  # [23, 45, 12, 34, 43]




# ============================================================
# PART 3: Linear Search
# ============================================================

# --- TASK 3A: Basic Linear Search ---
# Return the INDEX of target if found, -1 if not found.

def linear_search(items, target):
    """Search for target in items. Returns index or -1."""
    # YOUR CODE HERE:
    pass


# Test:
# print(linear_search([4, 2, 7, 1, 9], 7))   # Should print 2
# print(linear_search([4, 2, 7, 1, 9], 5))   # Should print -1



# --- TASK 3B: Search with Condition ---
# Find the FIRST number greater than threshold.
# Return the number itself (not index), or None if not found.

def find_first_greater(items, threshold):
    """Find first item greater than threshold."""
    # YOUR CODE HERE:
    pass


# Test:
# print(find_first_greater([3, 1, 4, 1, 5, 9], 4))  # Should print 5
# print(find_first_greater([3, 1, 4, 1, 5, 9], 10)) # Should print None




# ============================================================
# PART 4: PetShop Search Methods
# ============================================================

class Pet:
    def __init__(self, name, species):
        self.name = name
        self.species = species
        self.hunger = 50

    def __repr__(self):
        return f"Pet({self.name}, {self.species})"


class PetShop:
    def __init__(self):
        self.pets = []

    def add_pet(self, pet):
        self.pets.append(pet)

    # --- YOUR TASK: Complete these two methods ---

    def find_by_name(self, name):
        """
        Find a pet by name (case-insensitive).
        Returns: Pet if found, None if not found.
        """
        # YOUR CODE HERE:
        pass

    def find_hungry_pets(self, threshold=60):
        """
        Find ALL pets with hunger above threshold.
        Returns: list of matching pets.
        """
        # YOUR CODE HERE:
        pass


# Test your PetShop:
# shop = PetShop()
# shop.add_pet(Pet("Max", "dog"))
# shop.add_pet(Pet("Luna", "cat"))
# shop.add_pet(Pet("Buddy", "dog"))
#
# # Test find_by_name (case insensitive)
# print(shop.find_by_name("LUNA"))  # Pet(Luna, cat)
# print(shop.find_by_name("nemo"))  # None
#
# # Test find_hungry_pets
# shop.pets[0].hunger = 80
# shop.pets[2].hunger = 70
# print(shop.find_hungry_pets(60))  # [Pet(Max, dog), Pet(Buddy, dog)]




# ============================================================
# REFLECTION (Think about these)
# ============================================================
#
# 1. When would you use 'for' vs 'while'?
#
# 2. Why do we use 'break' when we find the item in linear search?
#
# 3. If you have 100 items, what's the worst-case number of
#    comparisons for linear search?
#
# ============================================================


# ============================================================
# DONE! Bring this to our next lesson.
# ============================================================
