#P1

def fun1(x):
	return x-2

def fun2(x):
	val = x + 10
	if(val == 0):
		return 1
	else:
		return val

dom1 = [-3, -2, -1, 0, 1, 2, 3]
dom2 = [-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5]

def encontrarCero(f, dom):
	for i in dom:
		if(f(i)==0):
			return i
	return "Nunca pasa por el eje x"

def encontrarCeroBin(f, dom):
	ini = 0
	fin = len(dom)
	val = "Nunca pasa por el eje x"
	while(ini < fin):
		mid = ini + (fin - ini)/2
		if(f(mid)<0):
			ini = mid
		elif(f(mid)>0):
			fin = mid
		else:
			val = mid
			break
	return val

"""
Que pasa si le doy un dominio muy grande a encontrarCero?
En que casos es mejor ocupar la lineal? Existen dicho casos?
""" 


		


#P2 
#A-Comida B-Personales C-Aseo
#clase cantidad precio unitario

stock = {"gomitas": ['A', 50, 200], "pasta de dientes": ['B', 30, 1000], "cloro": ['C',40, 2000]}

def valorStock(d):
	suma = 0
	for llave in d:
		valores = d[llave]
		suma += valores[1]*valores[2]
	return suma
	
def valorClase(d, clase):
	suma = 0
	for llave in d:
		valores = d[llave]
		if valores[0] == clase:
			suma += valores[1]*valores[2]
	return suma


def listaClase(d, clase):
	lista = []
	for llave in d:
		valores = d[llave]
		if valores[0] == clase:
			lista.append(llave)
	return lista

compras = {"gomitas": 5, "cloro": 10, "jugo": 2}

def actualizacion(d, dc):
	total = 0
	for llave in dc:
		if llave in d:
			valores = d[llave]
			valores[1] = valores[1] - dc[llave]
			total += valores[2]*dc[llave]
	return (d, total)		
