-
-
Save codecademydev/d8239d0d725f6bee4d88187989fb32eb to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
def estimated_insurance_cost(self): | |
try: | |
estimated_cost = 250 * self.age - 128 * self.sex + 370 * self.bmi + 425 * self.num_of_children + 24000 * self.smoker - 12500 | |
except TypeError: | |
print("Only Integers Are Allowed") | |
print(self.name + "’s estimated insurance costs is " + str(estimated_cost)) | |
def update_age(self, new_age): | |
self.age = new_age | |
print(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 new_num_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["BMI"] = self.bmi | |
patient_information["Number of Children"] = self.num_of_children | |
patient_information["Smoker"] = self.smoker | |
return patient_information | |
def update_bmi(self, new_bmi): | |
self.bmi = new_bmi | |
print(self.name + " has now a BMI of " + str(self.bmi) + ".") | |
self.estimated_insurance_cost() | |
def update_smoking_status(self, new_smoker): | |
self.smoker = new_smoker | |
if new_smoker == 1: | |
print(self.name + " has changed their status to smoker.") | |
else: | |
print(self.name + " has changed their status to non-smoker.") | |
self.estimated_insurance_cost() | |
patient1 = Patient("John Doe", 25, 1, 22.2, 0, 0) | |
#if not type(patient1.name) is str: | |
#raise TypeError("Only strings are allowed") | |
#if not type(patient1.age) is int: | |
#raise TypeError("Only integers are allowed") | |
#if not type(patient1.sex) is int: | |
#raise TypeError("Only integers are allowed") | |
#if not type(patient1.bmi) is float: | |
#raise TypeError("Only integers are allowed") | |
#if not type(patient1.num_of_children) is int: | |
#raise TypeError("Only integers are allowed") | |
#if not type(patient1.smoker) is int: | |
#raise TypeError("Only integers are allowed") | |
patient1.estimated_insurance_cost() | |
patient1.update_age(26) | |
patient1.update_num_children(2) | |
print(patient1.patient_profile()) | |
patient1.update_bmi(27.0) | |
patient1.update_smoking_status(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment