Bird
Raised Fist0
Drone Programmingprogramming~20 mins

Altitude limits configuration in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Altitude Mastery
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 altitude check code?
Given the drone altitude limits set between 10 and 120 meters, what will the program print when the altitude is 130?
Drone Programming
min_altitude = 10
max_altitude = 120
current_altitude = 130
if current_altitude < min_altitude:
    print("Below minimum altitude")
elif current_altitude > max_altitude:
    print("Above maximum altitude")
else:
    print("Altitude within limits")
AAbove maximum altitude
BBelow minimum altitude
CAltitude within limits
DNo output
Attempts:
2 left
💡 Hint
Check the condition that compares current altitude with max altitude.
Predict Output
intermediate
2:00remaining
What is the value of 'safe_to_fly' after running this code?
The drone must fly only if altitude is between 20 and 100 meters inclusive. What is the value of 'safe_to_fly' if altitude is 20?
Drone Programming
min_altitude = 20
max_altitude = 100
altitude = 20
safe_to_fly = min_altitude <= altitude <= max_altitude
AFalse
BTrue
CNone
DError
Attempts:
2 left
💡 Hint
Check if the altitude is within the inclusive range.
🔧 Debug
advanced
2:00remaining
What error does this altitude validation code raise?
Identify the error when running this code that checks if altitude is within limits.
Drone Programming
min_altitude = 15
max_altitude = 90
altitude = 50
if altitude > min_altitude and altitude < max_altitude:
    print("Altitude OK")
else:
    print("Altitude out of range")
ANameError: name 'altitude' is not defined
BTypeError: unsupported operand type(s) for >
CSyntaxError: expected ':' after else
DNo error, prints 'Altitude OK'
Attempts:
2 left
💡 Hint
Look carefully at the else statement syntax.
Predict Output
advanced
2:00remaining
How many altitude values are stored after this configuration?
The code stores altitude limits in a dictionary for different zones. How many zones are configured?
Drone Programming
altitude_limits = {
    'zone1': (10, 50),
    'zone2': (20, 80),
    'zone3': (15, 60),
    'zone4': (5, 100)
}
print(len(altitude_limits))
AError
B3
C5
D4
Attempts:
2 left
💡 Hint
Count the number of keys in the dictionary.
🧠 Conceptual
expert
3:00remaining
Which option correctly describes the effect of this altitude limit code snippet?
Consider this code snippet that sets altitude limits and checks a drone's altitude: min_altitude = 30 max_altitude = 90 altitude = 90 if altitude >= min_altitude and altitude <= max_altitude: status = "Safe" else: status = "Unsafe" What is the value of 'status' and why?
A"Safe" because altitude equals the maximum limit and the condition includes equality
B"Safe" because altitude is greater than min_altitude only
C"Unsafe" because altitude equals max_altitude which is not allowed
D"Unsafe" because altitude must be strictly less than max_altitude
Attempts:
2 left
💡 Hint
Check the comparison operators used in the condition.

Practice

(1/5)
1. What is the main purpose of using setAltitudeLimits(min, max) in drone programming?
easy
A. To control the drone's speed
B. To set the minimum and maximum altitude the drone can fly
C. To change the drone's camera angle
D. To start the drone's engine

Solution

  1. Step 1: Understand the function name and parameters

    The function setAltitudeLimits(min, max) clearly suggests setting limits related to altitude using minimum and maximum values.
  2. Step 2: Match the function purpose with options

    Among the options, only setting altitude boundaries matches the function's name and parameters.
  3. Final Answer:

    To set the minimum and maximum altitude the drone can fly -> Option B
  4. Quick Check:

    Altitude limits = min and max altitude [OK]
Hint: Look for min and max altitude in the function name [OK]
Common Mistakes:
  • Confusing altitude limits with speed control
  • Thinking it controls camera or engine
  • Ignoring parameter names min and max
2. Which of the following is the correct syntax to set altitude limits from 10 to 100 meters?
easy
A. setAltitudeLimits(10, 100);
B. setAltitudeLimits[10, 100];
C. setAltitudeLimits{10, 100};
D. setAltitudeLimits 10, 100;

Solution

  1. Step 1: Identify correct function call syntax

    Function calls use parentheses () with arguments separated by commas.
  2. Step 2: Check each option's syntax

    setAltitudeLimits(10, 100); uses parentheses and commas correctly. Options B and C use brackets or braces which are invalid for function calls. setAltitudeLimits 10, 100; misses parentheses.
  3. Final Answer:

    setAltitudeLimits(10, 100); -> Option A
  4. Quick Check:

    Function call syntax = parentheses ( ) [OK]
Hint: Function calls always use parentheses ( ) [OK]
Common Mistakes:
  • Using square brackets or braces instead of parentheses
  • Omitting parentheses around arguments
  • Missing commas between arguments
3. What will be the output of this code snippet?
setAltitudeLimits(50, 200);
print(getAltitudeLimits());

Assuming getAltitudeLimits() returns the current limits as a list [min, max].
medium
A. Error: function not defined
B. [200, 50]
C. [50, 200]
D. [0, 0]

Solution

  1. Step 1: Understand the function calls

    setAltitudeLimits(50, 200) sets the limits to minimum 50 and maximum 200. getAltitudeLimits() returns the current limits as a list [min, max].
  2. Step 2: Predict the output of print statement

    Since limits were set to 50 and 200, the output will be [50, 200].
  3. Final Answer:

    [50, 200] -> Option C
  4. Quick Check:

    Set then get limits = [50, 200] [OK]
Hint: Set limits first, then get returns same values [OK]
Common Mistakes:
  • Swapping min and max values in output
  • Assuming default limits without setting
  • Thinking function returns error
4. Identify the error in this code snippet:
setAltitudeLimits(150, 100);
print(getAltitudeLimits());

Assuming setAltitudeLimits(min, max) requires min < max.
medium
A. Minimum altitude is greater than maximum altitude
B. Missing semicolon after setAltitudeLimits
C. getAltitudeLimits() is not defined
D. No error, code runs fine

Solution

  1. Step 1: Check the order of min and max values

    The code calls setAltitudeLimits(150, 100) where min=150 and max=100, which violates the rule min < max.
  2. Step 2: Identify the error caused by invalid limits

    Since min is greater than max, this is an error in setting altitude limits.
  3. Final Answer:

    Minimum altitude is greater than maximum altitude -> Option A
  4. Quick Check:

    min < max required, here min=150 > max=100 [OK]
Hint: Min altitude must be less than max altitude [OK]
Common Mistakes:
  • Ignoring min < max rule
  • Thinking semicolon is mandatory in all languages
  • Assuming getAltitudeLimits() is undefined
5. You want to configure altitude limits so the drone flies only between 20 and 120 meters. Which code snippet correctly applies this and prevents invalid input?
hard
A. setAltitudeLimits(120, 20);
B. setAltitudeLimits(max, min); // with min=20, max=120
C. if (min > max) { setAltitudeLimits(min, max); }
D. if (min < max) { setAltitudeLimits(min, max); } else { print('Invalid limits'); } // with min=20, max=120

Solution

  1. Step 1: Check condition to validate inputs

    We must ensure min is less than max before setting limits to avoid errors.
  2. Step 2: Analyze each option's logic

    if (min < max) { setAltitudeLimits(min, max); } else { print('Invalid limits'); } // with min=20, max=120 checks if min < max and sets limits only if true, else prints error. Options A and B swap min and max incorrectly. if (min > max) { setAltitudeLimits(min, max); } uses wrong condition min > max.
  3. Final Answer:

    if (min < max) { setAltitudeLimits(min, max); } else { print('Invalid limits'); } // with min=20, max=120 -> Option D
  4. Quick Check:

    Validate min < max before setting limits [OK]
Hint: Always check min < max before setting limits [OK]
Common Mistakes:
  • Swapping min and max values
  • Using wrong condition for validation
  • Not handling invalid input cases