We start with the horizontal asymptote condition.
So we want `lim_(x->oo) kx + 1/x + 1 = 2`
This can't happen. The only options for the limits are 1 and `+- oo` So I'm guessing there are some parentheses missing.
So I'm going to guess that you meant:
`g(x) = a/("sin"^2 x) + 1 " when " x<pi/2,`
`g(x) = (kx+1)/x +1 " when " x >= pi/2`
`lim_(x->oo) (kx+1)/x + 1 = lim_(x->oo) (kx)/x + 1/x + 1 = k+1 = 2`
So we want k=1
`g(x) = (x+1)/x + 1 " when " x>= pi/2`
Now we want g to be continuous at `pi/2` so we need the right and left hand limits of g at `pi/2` to be equal:
`lim_((x-> (pi/2)^+)) (x+1)/x + 1 = ((pi/2)+1)/(pi/2)+1= 2 + 2/pi`
`lim_((x-> (pi/2)^-)) a/("sin"^2 x) + 1 = a/("sin"^2 pi/2) +1 = a+ 1`
So we want `a+1 = 2 + 2/pi`
`a = 1 + 2/pi`
Thus, g will have the desired properties if `k=1` and `a=1+2/pi`