Find an expression for the function and its probability density function. For a discrete function, you simply need a list of all the values the variable can take, and the probability of each. For continuous functions, an arithmetic expression of the probability as a function of the value of the variable is required.
Multiply each value of the function by its probability, then add these products together to get the expectation value of a discrete function.
Evaluate the integral of the product of the function and its probability function with respect to the variable to find the expectation value of a continuous function. Set the bounds of your integral according to the minimum and maximum values of the variable.