In this question, you want to first define the term “percent yield”. This is defined as the actual amount of product formed divided by the theoretical (or predicted) amount of product you could have formed times 100%. Or, actual/theoretical*100%.
So, you need to have two pieces of information: the actual yield of your product (which appears to be provided in the question), and the theoretical yield.
To calculate a theoretical yield, you need to determine how much product could be formed by using up all your limiting reactant(s). There are a few ways of determining this, but in this context, you should use stoichiometry to determine how much MgI2 would be formed under two scenarios: 1) using up all of your Mg (s), and 2) using up all of your I2 (s)
To do this, verify that your chemical equation is balanced. Once the equation is balanced, you can convert the amount of reactant into how much product would be made by using the coefficients of the balanced chemical equation. For example, if you had 2.5 moles of Mg, then you would do the following:
2.5 mole Mg * (1 mole MgI2/1 mole Mg) = 2.5 mole of MgI2. The ratio of MgI2 to Mg comes from the coefficients of 1 in the balanced chemical equation. You would then repeat that same process but using the amount of I2 that you have. Once you have computed the amount of product made under both scenarios, you need to compare these values. They will likely be different from each other. The lower one is the theoretical yield because it represents the amount of product that would be made once. The limiting reactant runs out.
Then, you can take your calculated theoretical yield and given actual yield to calculate the % yield.