Motivated by the discovery that living creatures may be able to enhance their locomotion capability through passive or active deformations of their wings or fins, we carry out a fully coupled fluid-structure interaction study to investigate the flapping motion of a foil with either chordwise or spanwise flexibility. We employ a fluid-structure interaction model, which accounts for fluid dynamics using the boundary-element method and structural dynamics using a two-dimensional nonlinear thin-plate model. With this approach, we numerically investigate the effect of structural deformation on the performance of the foil when it is immersed in two different fluids, a low-density fluid (e.g., air), in which the deformation is determined primarily by the inertia of the foil, and a high-density fluid (e.g., water), in which the fluid loading has a significant impact. In the first scenario, we find that the chordwise flexibility reduces both the thrust and the propulsion efficiency and the spanwise flexibility increases the thrust without efficiency reduction within a small range of structural parameters. In the second scenario, we find that the chordwise flexibility increase the efficiency. The spanwise flexibility, on the other hand, compromises the performance of the foil by diminishing both the thrust and the efficiency. Possible applications of these findings and their relation to designs in aquatic animals are discussed.