The question shows that the farmer has 17 sheep and all but 8 of them died. This sentence implies that all the sheep the farmer has died due to some reasons unknown except 8. That is, 9 sheep out of 17 died.
The mathematical representation of this is:
That is, the total number of sheep minus the sheep that are alive will give the number of sheep that died.
This farmer now has 8 sheep if all of the original 17 die except for 8. This is an example of a simple test of a) arithmetic b) attention to written instructions and c) deconstructing and understanding a sentence when it is barely grammatical and deliberately worded to confuse. It is a 'trick' question to see if the respondent will simply subtract 8 from 17 instead of fully reading the sentence (which is very badly constructed)