Discuss / Python / 为什么我写出来的显示name 'Cat'未定义?

为什么我写出来的显示name 'Cat'未定义?

Topic source

董DHH董

#1 Created at ... [Delete] [Delete and Lock User]
class Animal(object):
    def run(self):
        print('Animal is running')
class Dog(Animal):
    def run(self):
        print('dog is running')
class Cat(Animal):
    def run(self):
        print('cat is running')
    dog=Dog()
    dog.run()
    cat=Cat()
    cat.run()

董DHH董

#2 Created at ... [Delete] [Delete and Lock User]

我这个是在文本编辑器里面写的,用的dos命令窗口进行编译的,求大神指出哪里错了

董DHH董

#3 Created at ... [Delete] [Delete and Lock User]
class Animal(object):
    def run(self):
        print('Animal is running')
class Dog(Animal):
    def run(self):
        print('dog is running')
class Cat(Animal):
    def run(self):
        print('cat is running')
dog=Dog()
dog.run()

cat=Cat()
cat.run()

格式没弄对,这下好了


  • 1

Reply