0
0
Drone Programmingprogramming~20 mins

Formation flying basics in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Formation Flying Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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'])
A(15, 23)
B(5, 17)
C(15, 17)
D(10, 20)
Attempts:
2 left
💡 Hint
Add the leader's x and y to the drone's offset x and y respectively.
🧠 Conceptual
intermediate
1: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?
ALine formation
BV formation
CDiamond formation
DSquare formation
Attempts:
2 left
💡 Hint
Look at the y-coordinates of all drones.
🔧 Debug
advanced
2: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)
ASyntaxError due to incorrect dictionary comprehension syntax
BTypeError because of adding tuple and int
CKeyError because 'leader_pos' key missing
DNo error, outputs correct positions
Attempts:
2 left
💡 Hint
Check the placement of commas and parentheses in the dictionary comprehension.
📝 Syntax
advanced
2: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.
A
def calc_positions(leader, offsets):
    return {d: leader[0] + o[0], leader[1] + o[1] for d, o in offsets.items()}
B
def calc_positions(leader, offsets):
    return {d: (leader[0] + o[0]) + (leader[1] + o[1]) for d, o in offsets.items()}
C
def calc_positions(leader, offsets):
    return {d: leader[0] + o[0] + leader[1] + o[1] for d, o in offsets.items()}
D
def calc_positions(leader, offsets):
    return {d: (leader[0] + o[0], leader[1] + o[1]) for d, o in offsets.items()}
Attempts:
2 left
💡 Hint
Remember to return a tuple for each drone's position.
🚀 Application
expert
3: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))
A3
B2
C1
D4
Attempts:
2 left
💡 Hint
Sum the x and y offsets and check which are greater than 4.