40% of 120=48 black, so 120-48=72 are coloured. 37.5% (3/8) of 72=27 red, 29% of 72=0.29*72=21 green approx. So red+green=48 and 72-48=24 yellow. 24/120=1/5=20% of the 120 pens are yellow.
We don’t actually need to know there were 120 pens to work out the percentages. If 40% were black then 60% were coloured. 37.5% of these=22.5% red, and 29% of 60%=17.4% green. So 22.5+17.4=39.9%. That leaves 60-39.9=20.1% yellow.
The first way of working out the answer is easier to visualise because it deals with actual numbers of pens.