Python Control Flow: Medical Insurance Project - Task 10 (Extra)

has anyone got the code solution to Task 10 of Python Control Flow: Medical Insurance Project? codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-control-flow/projects/ds-python-controlflow-project

the instructions are:

  1. Use try and except statements to build error control into your code.
  2. In your analyze_bmi() function, notify the individual how much they need to lower their BMI to bring it to a normal weight range.
  3. Create a new function or code block that utilizes control flow in some way – feel free to experiment!

Please avoid requesting code solutions as per the forum guidelines. Since this a learning environment you’re not getting much out of copy/pasting solutions.

What you should do is attempt the problem and if you should get stuck then you can consider checking the forums. If you need to ask a question that’s not covered elsewhere please check the following FAQ first on how to ask good questions and thereby potentially receive the most helpful answers-

2 Likes

I’m also quite stuck on this try & except assignment. I tried it like the following:

try:
  def analyze_bmi(bmi_value):
    return bmi_value
except:
  if bmi <= 10:
    print("bmi input incorrect")
  else:
    print(bmi_value)

It does however not print anything. Is it because the try&except statements should be included in another function? If so, how exactly should the statements be denoted? I’m unsure about what statements follow ‘try’ and ‘except’.
Can someone help? :slight_smile: Merci!

It is because there isn’t really any reason for the

def analyze_bmi(bmi_value):
  return bmi_value

to throw an error. Why do you make a function that returns it’s parameter? Do you actually need the try…except here?