Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you assign attributes to your <code>player</code> in <code>__init__()</code>, they don't get created until <code>player</code> is instantiated. However, in your <code>soldier</code> class, you're trying to set <em>class</em> attributes <em>at class creation time</em> based on variables that don't exist at that time, because they only exist on instances (of a different class, no less).</p> <p>I think what you probably want to do is write an <code>__init__()</code> method for <code>soldier</code>. (I have also taken the liberty of capitalizing your class names per PEP 8. This helps keep track of which names refer to classes, i.e. <em>templates</em> for constructing objects, and which to instances of the classes.)</p> <pre><code>class Soldier(Player): def __init__(self, username, age, weight, height, gender): # call parent class to set up the standard player attributes Player.__init__(self, username, age, weight, height, gender) # now also define a soldier-specific attribute self.strength = weight*height*2 </code></pre> <p>And then <em>instantiate</em> the <code>Soldier</code> class rather than the <code>Player</code> class, since you want a soldier:</p> <pre><code>character_obj = Soldier(player_username, player_age, player_weight, player_height, player_gender) print character_obj.strength </code></pre> <p>I should further note that this:</p> <pre><code>class Soldier(Player): </code></pre> <p>is <em>not</em> a function call. You are not <em>passing</em> <code>Player</code> to <code>Soldier</code>. Instead you are saying that <code>Soldier</code> is a <em>kind of</em> <code>Player</code>. As such, it has all the attributes and capabilities of a <code>Player</code> (which you do not need to specify again, that's the whole point of inheritance) plus any additional ones you define in <code>Soldier</code>. However, you do not have direct access to the attributes of <code>Player</code> (or a <code>Player</code> instance) when declaring <code>Soldier</code> (not that you would ordinarily need them).</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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