Is it possible to write in a biological text that alleles learned to do something in order to achieve something else?
Of course, but only in the case that you are not a student who is writing a thesis work and expects to encounter an unfriendly or especially dense reviewer. It is usually completely clear from the context that you are not suggesting that alleles have the ability to plan their future behaviour in relation to achieving some future goal. It is, of course, possible to state quite correctly that plants form attractive flowers because the members of this species who accidentally gained this ability by mutation in the past better attracted pollinators than their competitors and thus had a greater number of progeny, who inherited this ability. However, it will be far easier to understand if we simply state that plants form flowers so that they can attract pollinators.