Bhodi's Tutoring - Dead by Daylight Edition
Exercise: Find the Closest Survivor (Python)
📋 Your Mission
Write a Python algorithm that helps the Killer find the closest Survivor. You'll need to:
- Calculate distances between the Killer and each Survivor
- Find the minimum distance among all Survivors
- Store the name of the closest Survivor in the variable
closest_survivor_name - Use the provided variables:
survivors(list) andkiller_location(number)
Important: Don't modify the given setup code - only write your algorithm below it!
💡 Hints
• Use abs() to calculate absolute distance: abs(killer_location - survivor.location)
• Loop through all survivors and keep track of the closest one found so far
• Remember to access survivor properties with survivor.name and survivor.location
📝 Given Setup Code (Read-Only)
class Survivor:
def __init__(self, name, location):
self.name = name
self.location = location
killer_location = 50
survivors = [
Survivor("Dwight", 10), # Distance: |50 - 10| = 40
Survivor("Meg", 30), # Distance: |50 - 30| = 20
Survivor("Claudette", 70), # Distance: |50 - 70| = 20
Survivor("Jake", 95) # Distance: |50 - 95| = 45
]
# Your algorithm goes below this line: