Python Classes: Medical Insurance Project

thank you so much! the review and the way u showed it made sense and I got it to work, as well as being able to do my own!

1 Like

don’t know if this is still relevant but here’s me piece of code about try and except

except TypeError:
  print("Incorrect operation for calculating estimated insurance cost. Please insert numerical value.")

Not sure why I’m getting an error here. Any ideas? I don’t see any syntax errors.

class Patient:

  def __init__(self, name, age, sex, bmi, num_of_children, smoker): = name

    self.age = age = sex

    self.bmi = bmi

    self.num_of_children = num_of_children

    self.smoker = smoker

  def estimated_insurance_cost(self):

    estimated_cost = 250 * self.age - 128 * + 370 * self.bmi + 425 * self.num_of_children + 24000 * self.smoker - 12500

    print("{Patient Name}’s estimated insurance costs is {estimated cost} dollars.".format(, estimated_cost)

patient1 = Patient("John Doe", 20, 1, 22.2, 0, 0)


 File "", line 14
    patient1 = Patient("John Doe", 20, 1, 22.2, 0, 0)
SyntaxError: invalid syntax

If you find a SyntaxError but the line itself makes sense have a look at the previous lines as it’s often a propagating issue like a missing parenthesis or similar.