###BACKGROUND:
Jacob recently decided to get healthy and lose some weight. He did a lot of reading and research and after focusing on steady exercise and a healthy diet for several months, was able to shed over 50 pounds! Now he wants to share his success, and has decided to tell his friends and family how much weight they could expect to lose if they used the same plan he followed.

Lots of people are really excited about Jacob's program and they want to know how much weight they would lose if they followed his plan. Unfortunately, he's really bad at math, so he's turned to you to help write a program that will calculate the expected weight loss for a particular person, given their weight and how long they think they want to continue the plan.

###TECHNICAL DETAILS:
Jacob's weight loss protocol, if followed closely, yields loss according to a simple formulae, depending on gender. Men can expect to lose 1.5% of their current body weight each week they stay on plan. Women can expect to lose 1.2%. (Children are advised to eat whatever they want, and make sure to play outside as much as they can!)

###TASK:
Write a function that takes as input:
```
- The person's gender ('M' or 'F');
- Their current weight (in pounds);
- How long they want to stay true to the protocol (in weeks);
```
and then returns the expected weight at the end of the program.

###NOTES:
Weights (both input and output) should be decimals, rounded to the nearest tenth.
Duration (input) should be a whole number (integer). If it is not, the function should round to the nearest whole number.
When doing input parameter validity checks, evaluate them in order or your code will not pass final tests.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def lose_weight(gender, weight, duration):
	

Solutions:
def lose_weight(gender, weight, duration):
	if not gender in ['M', 'F']:
		return 'Invalid gender'
	if weight <= 0:
		return 'Invalid weight'
	if duration <= 0:
		return 'Invalid duration'
	nl = 0.985 if gender == 'M' else 0.988
	for i in range(duration):
		weight *= nl
	return round(weight, 1)


RATES = {'M': (100 - 1.5) / 100, 'F': (100 - 1.2) / 100}

def lose_weight(gender, weight, duration):
	if gender not in RATES:
		return 'Invalid gender'
	if weight <= 0:
		return 'Invalid weight'
	if duration <= 0:
		return 'Invalid duration'
	rate = RATES[gender]
	return round(weight * rate ** duration, 1)


def lose_weight(gender, weight, duration):
	if gender not in ('M', 'F'):
		return 'Invalid gender'
	if weight <= 0:
		return 'Invalid weight'
	if duration <= 0:
		return 'Invalid duration'
	rate = 0.015 if gender == 'M' else 0.012
	for i in range(duration):
		weight = weight * (1 - rate)
	return float('{:.1f}'.format(weight))


def lose_weight(gender, weight, duration):
	if gender not in 'MF':
		return 'Invalid gender'
	if weight <= 0:
		return 'Invalid weight'
	if duration <= 0:
		return 'Invalid duration'
	if gender == 'M':
		loss = 1 - 1.5 / 100
	else:
		loss = 1 - 1.2 / 100
	return round(weight * loss ** duration, 1)


def lose_weight(gender, weight, duration):
	if gender not in ('M', 'F'):
		return 'Invalid gender'
	if weight <= 0:
		return 'Invalid weight'
	if duration <= 0:
		return 'Invalid duration'
	factor = 0.985 if gender == 'M' else 0.988
	expected_weight = factor ** duration * weight
	return round(expected_weight, 1)


lose_weight = lambda g, w, d: 'Invalid gender' if g not in 'MF' else 'Invalid weight' if w <= 0 else 'Invalid duration' if d <= 0 else round(w * (0.985 if g == 'M' else 0.988) ** round(d), 1)


def lose_weight(gender, weight, duration):
	if gender in 'MF':
		if weight > 0:
			if duration > 0:
				for i in range(duration):
					if gender == 'M':
						weight -= weight * 0.015
					else:
						weight -= weight * 0.012
				return round(weight, 1)
			return 'Invalid duration'
		return 'Invalid weight'
	return 'Invalid gender'


def lose_weight(gender, weight, duration):
	rate = {'M': 0.015, 'F': 0.012}
	if gender not in ('M', 'F'):
		return 'Invalid gender'
	elif weight <= 0:
		return 'Invalid weight'
	elif duration <= 0:
		return 'Invalid duration'
	else:
		return round(weight * (1 - rate[gender]) ** duration, 1)