title: Text Adventure in Python: Working with Classes and Inheritance
body: <p>I'm fairly new to the idea of classes and subclasses in Python. I've found some questions/answers here on Stackoverflow related to my question, but they don't seem really answer the specifics that I am looking for. I consulted YouTube and other websites, but I'm not having much luck. Now, I might be asking the wrong questions or looking in the wrong places.So, please bear with me for a bit. </p>
  
  <p>Now, I do understand how classes work in Python. That's not the problem.</p>
  
  <pre><code>class Person:
    def __init__(self, name, age):
      self.name = name
      self.age = age
  
  p1 = Person("John", 36)
  
  print(p1.name)
  print(p1.age)
  </code></pre>
  
  <p>This is a relatively basic concept that I think everyone can grasp. </p>
  
  <p>However, I'm having trouble understanding how subclasses work together and how to call up functions that are stored within a class. I want to add a function called "damage" to the class monster or person. I have tried making the class monster inherit the class person so that it also has its properties and can do damage to its health.</p>
  
  <p>I want to create something like this: </p>
  
  <pre><code>class character:
      def __init__(self, name, health ):
          self.name = name
          self.health = health
  
  class  monster(character):
      def __init__(self, name, health):
          character.__init__(self,name,health)
          self.health = health
          self.name = name
  
      def attack (self):
           self.health-1
  
  john=character("john",22)
  boo=monster("boo",20,22)
  monster.attack()
  </code></pre>
  
  <p>By invoking this code outside of the classes, I want to use the function attack so that the health of the user is reduced. </p>
  
  <p>I am still a novice and I have tried various methods.</p>
  
  <p>So that you get a better idea of what I mean, here is the reference code that I am trying to use:</p>
  
  <p><a href="https://trinket.io/python/07c3a147aa" rel="nofollow noreferrer">https://trinket.io/python/07c3a147aa</a></p>
  
  <p>Unfortunately, it's written in legacy code and I am not familiar with all the differences between 2.7 and 3.8. I've tried to adapt and to dissect the code so that I better understand the underlying processes, but I'm not having much luck. It keeps breaking in multiple spots and I keep on getting "Attribute Errors" all over the place. </p>
  
  <p>The thing that I really like about this code is that the character can enter a command like "help" or "attack" and then the function from the respective class is called up. I wanted to modify this code so that it better suits my needs like adding other functions and characters to it, but I am not really having much luck. </p>
  
  <p>If someone could help fix my very flawed code and thinking, I would very appreciative. </p>
  
  <p>I also thank you for taking the time out to read this.</p>
  
  <p>Christopher </p>