Challenge - 5 Problems
Geofence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of geofence boundary check
What is the output of this code that checks if a drone is inside a rectangular geofence boundary?
Drone Programming
geofence = {'min_lat': 10.0, 'max_lat': 20.0, 'min_lon': 30.0, 'max_lon': 40.0}
drone_position = {'lat': 15.0, 'lon': 35.0}
inside = (geofence['min_lat'] <= drone_position['lat'] <= geofence['max_lat']) and (geofence['min_lon'] <= drone_position['lon'] <= geofence['max_lon'])
print('Inside geofence' if inside else 'Outside geofence')Attempts:
2 left
💡 Hint
Check if the drone's latitude and longitude are within the min and max values of the geofence.
✗ Incorrect
The drone's latitude 15.0 is between 10.0 and 20.0, and longitude 35.0 is between 30.0 and 40.0, so it is inside the geofence.
🧠 Conceptual
intermediate1:00remaining
Understanding geofence polygon boundaries
Which data structure is best to represent a polygon geofence boundary for a drone?
Attempts:
2 left
💡 Hint
A polygon needs multiple points to define its shape.
✗ Incorrect
A polygon geofence is defined by multiple vertices, so a list of coordinate pairs is the best representation.
🔧 Debug
advanced1:30remaining
Fix the geofence boundary check error
This code is supposed to check if a drone is inside a geofence but raises an error. What is the error?
Drone Programming
geofence = {'min_lat': 10.0, 'max_lat': 20.0, 'min_lon': 30.0, 'max_lon': 40.0}
drone_position = {'lat': 25.0, 'lon': 35.0}
inside = (geofence['min_lat'] <= drone_position['lat'] <= geofence['max_lat']) and (geofence['min_lon'] <= drone_position['lon'] <= geofence['max_lon'])
print('Inside geofence' if inside else 'Outside geofence')Attempts:
2 left
💡 Hint
Check the drone's latitude value and the geofence limits.
✗ Incorrect
The drone's latitude 25.0 is outside the max_lat 20.0, so inside is false and output is 'Outside geofence'. No error occurs.
📝 Syntax
advanced1:00remaining
Identify the syntax error in geofence code
Which option contains a syntax error in defining a geofence dictionary?
Attempts:
2 left
💡 Hint
Look for missing punctuation in dictionary syntax.
✗ Incorrect
Option A is missing a colon between 'max_lon' and 40.0, causing a syntax error.
🚀 Application
expert2:30remaining
Calculate if drone is inside a polygon geofence
Given a polygon geofence defined by vertices and a drone position, which option correctly determines if the drone is inside the polygon using the ray casting algorithm?
Drone Programming
def is_inside_polygon(point, polygon): x, y = point inside = False n = len(polygon) p1x, p1y = polygon[0] for i in range(n + 1): p2x, p2y = polygon[i % n] if y > min(p1y, p2y): if y <= max(p1y, p2y): if x <= max(p1x, p2x): if p1y != p2y: xinters = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x if p1x == p2x or x <= xinters: inside = not inside p1x, p1y = p2x, p2y return inside polygon = [(0,0), (0,10), (10,10), (10,0)] drone = (5,5) print(is_inside_polygon(drone, polygon))
Attempts:
2 left
💡 Hint
The drone is inside the square polygon defined by the vertices.
✗ Incorrect
The drone point (5,5) lies inside the square polygon, so the function returns True.