I have two python files in the first one I have the parent class. I created a new file with the sub class. When I run the sub class file the methods in the parent class file run first the the sub class.
the parent class looks like this
class human():
def __init__ (self, gender="", age=0, height=0, howHigh=""):
#setting attributes
self.gender = ""
self.age = 0
self.height = 0
self.howHigh = ""
def setHeight(self):
self.height = int(input("What is your height in cm? "))
def setGender(self):
self.gender = input("What is your gender? ")
def setAge(self):
self.age = int(input("What is your age? "))
def changeHeight(self):
if self.height < 80:
self.howHigh = "Small"
print("Your hieght is small!")
elif self.height >= 80 and self.height < 180:
self.howHigh = "Medium"
print("Your hieght is medium!")
elif self.height >= 180:
self.howHigh = "Large"
print("Your hieght is tall")
human1 = human()
human1.setHeight()
human1.setGender()
human1.setAge()
print("human gender is ", human1.gender)
print("Human age is", human1.age)
print("Human height is", human1.height)
human1.changeHeight()
print(human1.howHigh)
human1 = human()
human1.setHeight()
human1.setGender()
human1.setAge()
print("human gender is ", human1.gender)
print("Human age is", human1.age)
print("Human height is", human1.height)
human1.changeHeight()
print(human1.howHigh)
the sub class file looks like this
from human_class import *
class child(human):
def __init__(self):
super().__init__()
def setHeight(self):
self.height = int(input("What is your height in cm? "))
def changeHeight(self):
if self.height < 30:
self.howHigh = "Small"
print("Your hieght is small for a child!")
elif self.height >= 30 and self.height < 120:
self.howHigh = "Medium"
print("Your hieght is medium for a child!")
elif self.height >= 120:
self.howHigh = "Large"
print("Your hieght is tall for a child!")
child1 = child()
child1.setHeight()
child1.changeHeight()
print(child1.howHigh)
The codes are below and when I run the parent class file human runs. When I run the second file, the child class, then methods for class human() run first then the methods for class child(human). What I want is to run the sub class file and have only those methods run. Is that possible, it happens most of the time i do this this way?
Thanks for your help