24.6k views
5 votes
Declare a class named PatientData that contains two attributes named height_inches and weight_pounds.

User Arnuschky
by
4.4k points

1 Answer

7 votes

Answer:

class PatientData:

def __init__(self, height_inches, weight_pounds):

self.height_inches = height_inches

self.weight_pounds = weight_pounds

a_patient = PatientData(75, 125)

print("Patient's height:", a_patient.height_inches)

print("Patient's weight:", a_patient.weight_pounds)

Step-by-step explanation:

Create a class named PatientData

Inside the class, create a constructor (def __init__), that takes two parameters, height_inches and weight_pounds. This is used to initialize the PatientData objects. Inside the constructor, set the height_inches and weight_pounds

Create PatientData object named a_patient. Note that in order to create an object, you need to specify the height_inches and weight_pounds

Then, you may access these values by typing the object name, ".", and variable name. For example, to access the height_inches, you should write the following:

→ a_patient.height_inches

Then, print the height and weight of the patient

User Cui Mingda
by
5.3k points