Suppose that the life expectancy for an average person is 70 years, and that this life expectancy can be adapted based on the following criteria:
for women, four years are added
for smokers, five years are subtracted and for non-smokers, five years are added
subtract 3 years for persons that never take part in any sport and add one year for every hour a person exercises a week
subtract half a year for every glass of alcohol consumed over the seven a person drinks a week (for a person that consumes eleven glasses of alcohol a week, two years are subtracted); add two years for those who don't drink any alcohol
for persons that don't eat fast food too often, three years are added
Based on the formula, the life expectancy of a male smoker that exercises only two hours a week, drinks ten glasses of alcohol a week and eats fast food fairly often, is 65.5 years.
Note: This is NOT a scientific prophecy. Those that have constructed this question can't be put responsible for wrong prophecies of the age you will die! I have considered a scientifically build questionnaire, but seeing as it asked questions concerning your stools, I decided to make one up myself.
Write a function life_expectancy to which the five parameters below should be passed:
sex: a string that indicates the sex of the person (man or woman)
smoker: a Boolean value that indicates whether the person smokes or not
sports: an integer that indicates how many hours the person exercises
alcohol: an integer that indicates the amount of glasses of alcohol the person drinks a week
fastfood: a Boolean value that indicates how much fast food is eaten
Based on the values given, the function should predict the life expectancy, and has to print this prognosis as a result. The result of the function should be given as an integer.
>>> life_expectancy(sex='man', smoker=True, sports=2, alcohol=10, fastfood=True)
65.5
>>> life_expectancy(sex='man', smoker=True, sports=5, alcohol=5, fastfood=True)
70.0
>>> life_expectancy(sex='woman', smoker=False, sports=5, alcohol=0, fastfood=False)
89.0
>>> life_expectancy(sex='woman', smoker=False, sports=3, alcohol=14, fastfood=True)
78.5
>>> life_expectancy(sex='man', smoker=False, sports=4, alcohol=4, fastfood=False)
82.0