The student needs to choose 5 books.
However, 2 books are compulsory, which means the student must choose these 2 books.
This leaves the student with 9 - 2 = 7 books to choose from.
The student needs to choose 5 - 2 = 3 more books from the remaining 7 books.
The number of ways to choose 3 books from 7 books is given by the combination formula:
$$ \binom{n}{k} = \frac{n!}{k!(n-k)!} $$
where $n$ is the total number of items and $k$ is the number of items to choose.
In this case, $n = 7$ and $k = 3$.
So the number of ways to choose 3 books from 7 books is:
$$ \binom{7}{3} = \frac{7!}{3!(7-3)!} = \frac{7!}{3!4!} = \frac{7 \times 6 \times 5}{3 \times 2 \times 1} = 7 \times 5 = 35 $$
Therefore, there are 35 ways in which a student can choose 5 out of 9 books if 2 are compulsory.
Final Answer: The final answer is $\boxed{35}$