probability of a and b formula code example Example 1: profit formula total revenue – total expenses = profit Example 2: basic probability theory P(A) = n(A)/n(S)