I was advised to re post this to be more clear.
Doing a class and finished with the rest less this one. Any guidance is appreciated. I have derived part of the question where I am stuck with to keep it short. I have also attached my working.
With my working below, I expect to be able to create a class containing one variable. I want to be able to change that variable and print the new variable. Example, change the value from horns = 2 to horns = 4. The question asks me specifically to use the 3 functions below to answer the question. With my current codes, I get an error message after I enter the value at the raw_input prompt.
Thanks in advance for help.
Question as follows:
Create a class with 1 variable in it holding its own properties. Provide the following 3 methods:
getvariable1() - use return key to return value of property 1
setvariable1() - This should allow new value to be specified for property 1 - additional parameter needed to accept input.
printerfun() - to print values of the variables for the object.
Create your own object of the class and call get & set methods for the object created. Use printerfun() method to check if the codes works.
My working:
class animal:
horns = 2
def printerfun(self):
print getHorns()
def getHorns(self): #don't get where I should call this
return self.horns
def setHorns(horns):
self.horns = horns
animal_1 = animal()
F1 = raw_input('Please enter number of horns: ')
setHorns(F1)