A return function is slightly different from the functions you just saw. A return function returns a value or set of values. The values that are returned are called return values. Very creative, we know.
One real-life example of a return function is a calculator. You input an equation, and once you hit the equal sign, the calculator returns an answer! In this activity, your CoDrone Mini will simulate a calculator. After adding two numbers in the return function together, it will throttle up and down for the value of the answer.
After importing the CoDrone Mini and time libraries, creating the drone object, and pairing, define a function called
add with x and y as parameters. Underneath, have the function return
drone = CoDrone_mini.CoDrone()
Create a variable called
answer that will store the return function. Next, include a print command that will display “The answer is” along with the answer.
answer = add(2, 3)
print(“The answer is “, answer)
Program your drone to take off, and then create a for loop with
answer as its parameter. Within the loop, have the drone throttle up for half a second at 30% power, and then down for the same amount of time and power. Finally, have the drone land.
for i in range(answer):