Challenge - 5 Problems
Waypoint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Waypoint acceptance with radius check
What is the output of this code that checks if a drone has reached a waypoint within a given radius?
Drone Programming
def has_reached_waypoint(drone_pos, waypoint_pos, radius): dx = drone_pos[0] - waypoint_pos[0] dy = drone_pos[1] - waypoint_pos[1] distance_squared = dx*dx + dy*dy return distance_squared <= radius*radius print(has_reached_waypoint((10, 10), (13, 14), 5))
Attempts:
2 left
💡 Hint
Remember to compare squared distances to avoid costly square root calculations.
✗ Incorrect
The squared distance between (10,10) and (13,14) is 3^2 + 4^2 = 9 + 16 = 25. The radius squared is 5^2 = 25. Since 25 <= 25, the function returns True.
❓ Predict Output
intermediate2:00remaining
Effect of waypoint radius on acceptance
Given this code, what will be the output when the drone is exactly on the edge of the acceptance radius?
Drone Programming
def check_acceptance(drone_pos, waypoint_pos, radius): from math import sqrt distance = sqrt((drone_pos[0] - waypoint_pos[0])**2 + (drone_pos[1] - waypoint_pos[1])**2) return distance < radius print(check_acceptance((0, 0), (3, 4), 5))
Attempts:
2 left
💡 Hint
Check the comparison operator used for acceptance.
✗ Incorrect
The distance between (0,0) and (3,4) is 5. The function returns True only if distance < radius, so 5 < 5 is False.
🔧 Debug
advanced2:00remaining
Identify the error in waypoint acceptance logic
This code is supposed to return True if the drone is within the radius of the waypoint. What error will it raise or what is the output?
Drone Programming
def is_within_radius(drone, waypoint, radius): distance = ((drone.x - waypoint.x)**2 + (drone.y - waypoint.y)**2)**0.5 if distance <= radius: return True else: return False class Point: def __init__(self, x, y): self.x = x self.y = y print(is_within_radius(Point(1,2), Point(4,6), 5))
Attempts:
2 left
💡 Hint
Check the if-else syntax carefully.
✗ Incorrect
The else statement is missing a colon, causing a SyntaxError.
❓ Predict Output
advanced2:00remaining
Waypoint acceptance with 3D coordinates
What is the output of this code that checks if a drone is within a 3D waypoint radius?
Drone Programming
def within_radius_3d(drone_pos, waypoint_pos, radius): dx = drone_pos[0] - waypoint_pos[0] dy = drone_pos[1] - waypoint_pos[1] dz = drone_pos[2] - waypoint_pos[2] dist_sq = dx*dx + dy*dy + dz*dz return dist_sq <= radius*radius print(within_radius_3d((1,2,3), (4,6,7), 6))
Attempts:
2 left
💡 Hint
Calculate squared distance in 3D and compare with squared radius.
✗ Incorrect
Distance squared is (1-4)^2+(2-6)^2+(3-7)^2 = 9+16+16=41. Radius squared is 36. 41 <= 36 is False, so output should be False.
❓ Predict Output
expert2:00remaining
Dynamic waypoint acceptance with variable radius
What is the output of this code that dynamically adjusts acceptance radius based on drone speed?
Drone Programming
def dynamic_acceptance(drone_pos, waypoint_pos, speed): base_radius = 5 radius = base_radius + speed * 0.5 dx = drone_pos[0] - waypoint_pos[0] dy = drone_pos[1] - waypoint_pos[1] dist_sq = dx*dx + dy*dy return dist_sq <= radius*radius print(dynamic_acceptance((0,0), (6,8), 4))
Attempts:
2 left
💡 Hint
Calculate radius including speed factor and compare squared distances.
✗ Incorrect
Distance squared is 6^2 + 8^2 = 36 + 64 = 100. Radius is 5 + 4*0.5 = 7. Radius squared is 49. 100 <= 49 is False, so output should be False.