I’m trying to solve this question:
http://www.pyschools.com/quiz/view_question/s3-q6
Write a function using ‘if/elif/else’ conditionals to compute the BMI of a person, and return the risk associated with cardiovascular diseases.
BMI = weight(kg)/( height(m)*height(m) )
BMI Risk
27.5 and above High Risk
23 – 27.4 Moderate Risk
18.5 – 22.9 Low Risk
Below 18.5 Risk of nutritional deficiency diseases
Examples
HealthScreen(85, 1.75)
‘Your BMI is 27.8 (High Risk).’
HealthScreen(68, 1.65)
‘Your BMI is 25.0 (Moderate Risk).’
HealthScreen(60, 1.63)
‘Your BMI is 22.6 (Low Risk).’
HealthScreen(40,1.58)
‘Your BMI is 16.0 (Risk of nutritional deficiency diseases).’
However I fail the Private Test Cases with this code
def HealthScreen(weight, height):
bmi = round(weight/(float(height)*height),1)
retv = "Your BMI is " +str(bmi)
if bmi >= 25.5:
retv += " (High Risk)."
elif bmi >=23 and bmi <=27.4:
retv += " (Moderate Risk)."
elif bmi >= 18.5 and bmi <=22.9:
retv += " (Low Risk)."
elif bmi <18.5:
retv += " (Risk of nutritional deficiency diseases)."
return retv
I know the code isn’t very pretty, but it went trough a lot of trial and error. I thought about adding code to check if either of the given numbers is zero, but still failed.
What am I not seeing?
You specify >= 25.5 but in the instructions it specifies high risk is for a BMI over 27.5