You're playing a game with a friend involving a bag of marbles. In the bag are ten marbles:

* 1 smooth red marble
* 4 bumpy red marbles
* 2 bumpy yellow marbles
* 1 smooth yellow marble
* 1 bumpy green marble
* 1 smooth green marble

You can see that the probability of picking a smooth red marble from the bag is `1 / 10` or `0.10` and the probability of picking a bumpy yellow marble is `2 / 10` or `0.20`.

The game works like this: your friend puts her hand in the bag, chooses a marble (without looking at it) and tells you whether it's bumpy or smooth. Then you have to guess which color it is before she pulls it out and reveals whether you're correct or not.

You know that the information about whether the marble is bumpy or smooth changes the probability of what color it is, and you want some help with your guesses.

Write a function `color_probability()` that takes two arguments: a color (`'red'`, `'yellow'`, or `'green'`) and a texture (`'bumpy'` or `'smooth'`) and returns the probability as a decimal fraction accurate to two places.

The probability should be a string and should discard any digits after the 100ths place. For example, `2 / 3` or `0.6666666666666666` would become the string `'0.66'`. Note this is different from rounding.

As a complete example, `color_probability('red', 'bumpy')` should return the string `'0.57'`.

Difficulty: EASY
Tags: Fundamentals

Starter code:
def color_probability(color, texture):
	

Solutions:
def color_probability(color, texture):
	marbles = {'smooth': {'red': 1, 'yellow': 1, 'green': 1, 'total': 3}, 'bumpy': {'red': 4, 'yellow': 2, 'green': 1, 'total': 7}}
	return '{}'.format(marbles[texture][color] / marbles[texture]['total'])[:4]


def color_probability(color, texture):
	prob_mapper = {'smooth': {'red': 1, 'yellow': 1, 'green': 1, 'total': 3}, 'bumpy': {'red': 4, 'yellow': 2, 'green': 1, 'total': 7}}
	prob = prob_mapper[texture][color] / prob_mapper[texture]['total']
	return str(prob)[:4]


def color_probability(color, texture):
	if texture == 'smooth':
		return '0.33'
	if color == 'red':
		return '0.57'
	if color == 'yellow':
		return '0.28'
	if color == 'green':
		return '0.14'


PROBS = [[1, 1, 1], [4, 2, 1]]
IDX = {'red': 0, 'yellow': 1, 'green': 2, 'smooth': 0, 'bumpy': 1}

def color_probability(color, texture):
	prob = PROBS[IDX[texture]][IDX[color]] / sum(PROBS[IDX[texture]])
	return '{:.2}'.format(int(prob * 100) / 100)


def color_probability(color, texture):
	if texture == 'bumpy':
		if color == 'red':
			prob = 4 / 7
		elif color == 'yellow':
			prob = 2 / 7
		else:
			prob = 1 / 7
	else:
		prob = 1 / 3
	return str(prob)[:4]


def color_probability(color, texture):
	bag = [('red', 'smooth'), ('red', 'bumpy'), ('red', 'bumpy'), ('red', 'bumpy'), ('red', 'bumpy'), ('yellow', 'bumpy'), ('yellow', 'bumpy'), ('yellow', 'smooth'), ('green', 'bumpy'), ('green', 'smooth')]
	candidates = [marble for marble in bag if marble[1] == texture]
	return '{:.03}'.format(sum((marble[0] == color for marble in candidates)) / len(candidates))[:-1]


from decimal import *

def color_probability(color, texture):
	bag_content = {('red', 'smooth'): 1, ('red', 'bumpy'): 4, ('yellow', 'bumpy'): 2, ('yellow', 'smooth'): 1, ('green', 'bumpy'): 1, ('green', 'smooth'): 1}
	color_match_number = Decimal(bag_content[color, texture])
	texture_match_list = [bag_content[k] for k in bag_content.keys() if k[1] == texture]
	texture_match_number = Decimal(sum(texture_match_list))
	return str(Decimal(color_match_number / texture_match_number).quantize(Decimal('.01'), rounding=ROUND_DOWN))


D = {'bumpy': {'red': '0.57', 'yellow': '0.28', 'green': '0.14'}, 'smooth': {'red': '0.33', 'yellow': '0.33', 'green': '0.33'}}

def color_probability(color, texture):
	return D[texture][color]


color_probability = lambda c, t, p=lambda x: x[0] in 'bg': f"{([[2, 1][p(c)], 4][c[0] == 'r'] if p(t) else 1) / (7 if p(t) else 3):.3f}"[:-1]