Challenge - 5 Problems
Formation Flying Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this drone formation position update?
Consider a drone formation where each drone updates its position based on the leader's position plus an offset. What will be the new position of drone B after running the code?
Drone Programming
leader_position = (10, 20) drone_offsets = {'A': (0, 0), 'B': (5, -3), 'C': (-4, 2)} new_positions = {drone: (leader_position[0] + offset[0], leader_position[1] + offset[1]) for drone, offset in drone_offsets.items()} print(new_positions['B'])
Attempts:
2 left
💡 Hint
Add the leader's x and y to the drone's offset x and y respectively.
✗ Incorrect
Drone B's new position is calculated by adding its offset (5, -3) to the leader's position (10, 20), resulting in (15, 17).
🧠 Conceptual
intermediate1:30remaining
Which formation pattern is represented by these relative positions?
Given the relative positions of drones from the leader as: {'A': (0, 0), 'B': (5, 0), 'C': (10, 0), 'D': (15, 0)}, what formation shape do they form?
Attempts:
2 left
💡 Hint
Look at the y-coordinates of all drones.
✗ Incorrect
All drones have the same y-coordinate (0) and increasing x-coordinates, so they form a straight line.
🔧 Debug
advanced2:30remaining
Why does this formation update code raise an error?
This code is intended to update drone positions but raises an error. Identify the cause.
Drone Programming
leader_pos = (10, 10) drone_offsets = {'A': (1, 2), 'B': (3, 4)} new_positions = {drone: (leader_pos[0] + offset[0], leader_pos[1] + offset[1]) for drone, offset in drone_offsets.items()} print(new_positions)
Attempts:
2 left
💡 Hint
Check the placement of commas and parentheses in the dictionary comprehension.
✗ Incorrect
The dictionary comprehension is missing parentheses around the tuple for the value, causing a syntax error.
📝 Syntax
advanced2:00remaining
Which option correctly defines a function to calculate drone formation positions?
Select the correct function syntax that takes leader position and offsets dict, and returns new positions dict.
Attempts:
2 left
💡 Hint
Remember to return a tuple for each drone's position.
✗ Incorrect
Option D correctly returns a dictionary with drone keys and tuple values representing positions.
🚀 Application
expert3:00remaining
How many drones are in formation after this update?
Given the code below, how many drones have updated positions stored in new_positions?
Drone Programming
leader = (0, 0) drone_offsets = {'A': (1, 1), 'B': (2, 2), 'C': (3, 3), 'D': (4, 4)} new_positions = {} for drone, offset in drone_offsets.items(): if offset[0] + offset[1] > 4: new_positions[drone] = (leader[0] + offset[0], leader[1] + offset[1]) print(len(new_positions))
Attempts:
2 left
💡 Hint
Sum the x and y offsets and check which are greater than 4.
✗ Incorrect
Only drones 'C' (3+3=6) and 'D' (4+4=8) have sums greater than 4, so 2 drones are in new_positions.