code: def arm_and_takeoff(aTargetAltitude):
      
  
      # Don't try to arm until autopilot is ready
      while not vehicle.is_armable:
          print(" Waiting for vehicle to initialise...")
          time.sleep(1)
          
      # Set mode to GUIDED for arming and takeoff:
      while (vehicle.mode.name != "GUIDED"):
          vehicle.mode = VehicleMode("GUIDED")
          time.sleep(0.1)
  
      # Confirm vehicle armed before attempting to take off
      while not vehicle.armed:
          vehicle.armed = True
          print(" Waiting for arming...")
          time.sleep(1)
  
      print(" Taking off!")
      vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude
  
      # Wait until the vehicle reaches a safe height 
      # before allowing next command to process.
      while True:
          requiredAlt = aTargetAltitude*0.95
          #Break and return from function just below target altitude.        
          if vehicle.location.global_relative_frame.alt>=requiredAlt: 
              print(" Reached target altitude of ~%f" % (aTargetAltitude))
              break
          print(" Altitude: %f < %f" % (vehicle.location.global_relative_frame.alt,
                                        requiredAlt))
          time.sleep(1)
docs: Arms vehicle and fly to aTargetAltitude.