Your question isn't immediately obvious to a native speaker because of how a native speaker would intend that sentence. I didn't even catch the nuance until it was pointed out in the comments on the question.
Individual Sports
The word "sport" can describe virtually any physical activity engaged in for pleasure or recreation (see M-W). It can be a solo activity, a group activity, or a team activity, and it may or may not be a competitive activity.
There are many words that describe involvement in various sports, such as "play", "participate", "practice", "compete", "take part", etc. Idiomatically, different "involvement" words are associated with different sports. So if you ask someone whether they are involved in a specific sport, you would use one of the involvement words associated with that sport.
Do you play hockey?
Do you practice swimming?
Do you participate in pole vaulting?
Do you go deep sea fishing?
Note that some sports don't even require an involvement word: "Do you swim?", "Do you pole vault?"
Sports Generically
The different involvement words vary as to how generic they are. I can't think of one that goes well with all sports (with the exception of the totally generic "do", as suggested in comments). They all (except for "do"), have a nuance, such as whether they are typically applied to an individual or group activity, a competitive activity, etc.
So when someone asks generically whether you are involved with any sports, the involvement word tends to be used generically. People simply pick almost any one of the involvement words to ask the question, with the word choice perhaps subconsciously triggered by a sport that happens to pop into their mind when they ask the question.
Even though "do" is generic and might be the "best" word to use for this question, it doesn't necessarily come to mind because many other words are more closely associated with sports. When you refer to involvement in a particular sport, "do" wouldn't be as commonly used a term as one associated with the sport.
Question Intent and Meaning
At least in conversation, the choice of involvement word is not meant to exclude sports with which that word is not normally associated when referring to a specific sport. So "do you play any sports" is not intended to ask:
Are you involved in any of the sports with which the word "play" is associated?
It means:
Do you engage in any physical activity for recreation?
A question like "Do you play any sports?" is, by nature, generic because the key words have different meanings to different people. As discussed in the comments, there is not unanimous agreement on what is and isn't a sport. And each involvement word carries different connotations to different people as to what sport-related characteristics define its usage.
So the person asking the question recognizes that the question can be interpreted many different ways. When asked in such an ambiguous way, the objective is not a precisely targeted answer. The asker doesn't intend the question to be parsed as to the precise meaning of the involvement word or the term "sports". And they don't expect a response of "well, that depends on what you define as a sport and what you mean by "play."
These kinds of open-ended questions are intended as conversation starters. The person isn't looking for a simple yes or no answer. The typical response would at least mention the sport or sports the person engages in, and might include more information or lead to a discussion about it.
Customary Response
In your example, the response to "Do you play any sports?" would typically be at least, "Yes, I swim", and might go on to include more description.
Note that the involvement word used in the question is a generic placeholder for the concept of involvement. When responding with a specific sport, you would use an involvement word appropriate to that sport rather than repeating the one in the question. So the response to "Do you play any sports?" could be:
Yes, I practice swimming.
Yes, I participate in pole vaulting.
Yes, I go deep sea fishing.
Ambiguity
That said, someone unfamiliar with the idiomatic usage could interpret "play" more literally, or perhaps try to second guess the asker's intended meaning (maybe the asker doesn't consider certain activities sports).
Keep in mind that this is not a question in a "legal" setting, where you are swearing to your response under oath and an imprecise answer could put you in jeopardy. Also, an imprecise answer would not offend the asker. In fact, if the asker hadn't thought of swimming as a sport, your interpreting it that way might well lead to a conversation about it, which is typically the intent of such a question.
But because the usual generic usage of terms is ambiguous, either yes or no could technically be a correct answer; "yes, I swim" or "no, but I swim" would both be legitimate. The asker could also read into either one your own perspective on whether you consider swimming a sport. This is a little like, "yes, we have no bananas"; ambiguous usage can technically be answered multiple ways and native speakers are familiar with the common usage and intent.
Caveat
Your question asks this in the context of an IELTS exam question rather than conversational usage. I'm not familiar with the exam and have no idea whether such a question is asking about normal conversational usage or literal nuances in word meaning.