This is probably a common error that many people get, but for me, I am trying to create a mythical creature generator where you can add and change attributes. Here is my code so far:
class Creature:
def __init__(self):
self.name = None
self.feet = None
self.inches = None
self.weight = None
self.gender = None
def getName(self):
return "Name: {}".format(self.name)
def setName(self, name):
self.name = name
def getHeight(self):
return "Height: {} ft. {} in.".format(self.feet, self.inches)
def setHeight(self, feet, inches):
self.feet = feet
self.inches = inches
def getWeight(self):
return "Weight: {} lbs.".format(self.weight)
def setWeight(self, weight):
self.weight = weight
def getGender(self):
return "Gender: {}".format(self.gender)
def setGender(self, index):
genders = ['Male', 'Female', 'Others']
if index == 0:
self.gender = genders[0]
elif index == 1:
self.gender = genders[1]
elif index == 2:
self.gender = genders[2]
a = Creature()
a.setGender(input('Enter a value to set gender; 0 = male, 1 = female, 2 = others: '))
print(a.getGender())
However, my problem is how the setter/getter method for gender works. Even if I type in 0, 1, or 2 (the proper input values), I still get None returned to me. Had I not set up a None value in the constructor, I would've gotten an attribute error. I am trying to make it so that when I input in 0, I get male, 1 if female, and 2 if other. I did not include a condition where you must input a value again if input is too high or not an int.