You can get away by just stating this: The rational numbers Q are dense in the field of real numbers R or a little less formally, between any two real numbers you will find a rational number.
The proof uses a property of real numbers known as the Archimedean property that states that given real numbers x,y with x>0, we can find a +ve integer n such that nx>y. This in turn is derived from the fact that a set of real numbers bounded above has a least upper bound in R
Now we are out to prove that if we have x<y then there is a rational number q such that x<q<y
From the archimedean property, since y-x>0, we have n(y-x)>1 for some natural number n.
Now there exist an integer m such that
m-1≤nx<m
Hence we have nx<m<1+nx<ny
So, nx<m<ny
So that x<m/n<y and since m and n are integers, q =m/n is the rational number that we are seeking.
Now coming to the question.
Let us say that f(x) is not a constant. Suppose f(x1) = c1 and f(x2) = c2 and say c1<c2
According to the problem statement c1 and c2 are both irrational. From the result above we have a rational number q such that c1<q<c2
Since f(x) is continuous, by Bolzano's theorem, we have x in the interval (x1, x2) such that f(x) = q contradicting the fact that f(x) takes on only irrational values
Hence f(x) is forced to be a constant
Now it is easy to see why option B is correct