Attribute error why Enumerated data type?

32 Views Asked by At

It will work if I do AnimalsENUM(35).Name = 'TIGER', but not if I set the Name with a function. Why?

class AnimalsENUM():
    def __init__(self,N):
        try:
            if N not in range(101):
                raise ValueError
        except ValueError:
            print("Animal Number %s is not vaild" % (Number))
        self.__Number = N
        self.__Name = ''
        self.__Age = None
        self.__Location = None

Function to set the name

def SetName(self):
    while True:
        try:
            Name = str(input("input name in all caps"))
            if Name not in ('TIGER', 'MONKEY','ELEPHANT', None):
                raise ValueError
            break
        except ValueError:
            print("Animal name %s not valid" % (Name))
    self.__Name = Name

def SetLocation__(self):
        while True:
            try:
                Location = int(input("input name in all caps"))
                if Location not in range(21):
                    raise ValueError
            except ValueError:
                print("Animal Location %s not vaild" % (Location))
        self.__Location = Location

def SetAge(self):
        while True:
            try:
                Age = int(input("input name in all caps"))
                if Age not in (range(100)):
                    raise ValueError
            except ValueError:
                print("Animal Age %s not vaild" % (Age))

I should be able to print this and print the animal name all in caps

c = AnimalsENUM(25)
c.SetName()
print(c.Name)
0

There are 0 best solutions below