Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're trying to use basic Object Oriented Programming, but need to understand that classes define objects and have properties.</p> <p>In the below code we define a Patient class:</p> <pre><code>class Patient: def __init__(self, name, age): self.name = name self.age = age def display(self): return "%s - %s"%(self.age, self.name) </code></pre> <p>This has a method called <code>__init__</code> which is defined by Python as the method called when initialising a new object from a class, and has several parameters:</p> <ul> <li>self - is a reference to the object we are creating and we won't go into here. But for now understand that the first parameter passed to an object method is a reference to itself.</li> <li>name - The name of the patient, which we define</li> <li>age - The age which we also define</li> </ul> <p>The second methods, is a method we can call on the object to have it return a way that we might want to print it out.</p> <p>Below we have code that creates a patient, and prints a representation of it from the display method.</p> <pre><code>firstpatient=patients(name, 16) print firstpatient.display() </code></pre> <p>Below is a section of code that could be used to build an array of patients for us to work with at a later stage.</p> <pre><code>patients = [] # make an array with nopatients. def getAnotherPatient(): name = input("what's your name") age = input("what's your age") patients.append(Patient(name,age)) # Add a new patient while somecondition: getAnotherPatient() </code></pre> <p>Once we've build a list of patients in the <code>patients</code> array, we could then loop through the objects within that and then manipulate or display them as per normal.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload