Traceback (most recent call last) error:
Question: Please help me n this i am not able to run getting error:

    
    
    Error: File "C:/Python34/pyt.py", line 6, in <module>  class Animal1: File "C:/Python34/pyt.py", line 30, in Animal1     cat = Animal1("cat",7) NameError: name 'Animal1' is not defined
    

Code:

    
    
    import random
    import sys
    import os
    
    
    class Animal1:
        __name = ""
        __age = 0
    
        def __init__(self,name,age):
            self.__nae = name
            self.__age = age
    
        def set_name(self,__name):
            self.__name = __name
    
        def get_name(self):
            return self.__name
    
        def set_age(self,__age):
            self.__age = age
    
        def get_age(self):
            self.__age
    
    
        def toPrint(self):
            return "Animal is {} and age is {}"
    
        cat = Animal1("cat",7)
        print(cat.toPrint())
    


Answer: I don't know what your code is really like, but it should be like this:

    
    
    class Animal1(object):
    
        def __init__(self, name, age):
            self.__name = name
            self.__age = age
    
        def set_name(self,__name):
            self.__name = __name
    
        def get_name(self):
            return self.__name
    
        def set_age(self,__age):
            self.__age = age
    
        def get_age(self):
            self.__age
    
        def toPrint(self):
            return "Animal is %s and age is %s" % (self.__name, self.__age)
    
    cat = Animal1("cat", 7)
    print(cat.toPrint())
    

