Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 7, 2020 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/52bacb772d59802e3c689ad3ff13f9d1 to your computer and use it in GitHub Desktop.
Save codecademydev/52bacb772d59802e3c689ad3ff13f9d1 to your computer and use it in GitHub Desktop.
Codecademy export
class Error(Exception):
pass
class ZerooronevalueError(Error):
pass
class NumericalvalueError(Error):
pass
class Patient:
def __init__(self, name, age, sex, bmi, num_of_children, smoker):
self.name = name
self.age = age
# add more parameters here
self.sex = sex
self.bmi = bmi
self.num_of_children = num_of_children
self.smoker = smoker
try:
if not isinstance(self.sex, int):
raise NumericalvalueError
if self.sex != 0 or self.sex != 1:
raise ZerooronevalueError
except NumericalvalueError:
print("Sex should be numerical value.")
except ZerooronevalueError:
print("Sex can be only '0' for Female or '1' for Male.")
def estimated_insurance_cost(self):
estimated_cost = 250 * self.age - 128 * self.sex + 370 * self.bmi + 425 * self.num_of_children + 24000 * self.smoker - 12500
print(str(self.name) + "'s estimated insurance costs is " + str(estimated_cost) + " dollars.")
def update_age(self, new_age):
self.age = new_age
print(str(self.name) + " is now " + str(self.age) + " years old.")
self.estimated_insurance_cost()
def update_num_children(self, new_num_children):
self.num_of_children = new_num_children
if self.num_of_children == 1:
print(self.name + " has " + str(self.num_of_children) + " child.")
else:
print(self.name + " has " + str(self.num_of_children) + " children.")
self.estimated_insurance_cost()
def patient_profile(self):
patient_information = {}
patient_information['Name'] = self.name
patient_information['Age'] = self.age
patient_information['Sex'] = self.sex
patient_information['BMI'] = self.bmi
patient_information['Number of Children'] = self.num_of_children
patient_information['Smoker'] = self.smoker
return patient_information
patient1 = Patient("John Doe", 25, 1, 22.2, 0, 0)
patient1.estimated_insurance_cost()
patient1.update_age(26)
patient1.update_num_children(1)
print(patient1.patient_profile())
patient2 = Patient("Doraemon", 25, 'Male', 22.2, 0, 0)
print(patient2.patient_profile())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment