def choose(n, r):
    """The number of ways of choosing r items from n"""
    if n < 0 or r < 0:
        print('Negative values not allowed')
        return 0
    if r > n:
        print('r must not be greater than n')
        return 0

    combin = 1
    if r > n / 2:
        r1 = n - r
    else:
        r1 = r
    for k in range(r1):
        combin = combin * (n - k) // (k + 1)

    return combin