import math


def entropy(p, n):
	""" Calculates entropy"""
	if(p == 0 and n == 0):
		ent = 0
	elif(p == 0):
		ent = -(n/(p + n))*math.log((n/(p + n)), 2)
	elif(n == 0):
		ent = -(p/(p + n))*math.log((p/(p + n)), 2)
	else:
		ent = -(p/(p + n))*math.log((p/(p + n)), 2) -(n/(p + n))*math.log((n/(p + n)), 2)
	return ent