我編寫了這個程序來學習OOP的基礎知識。當我在Python Shell中從IDLE運行該程序時,它不會顯示任何錯誤,但也不會顯示任何內容......我不知道如何確定我的錯誤。Python shell顯示沒有錯誤,但程序不運行
這裏是我的代碼:
class Shapes(object):
def __init__(self, width, length):
object.__init__(self)
self.setWidth(width)
self.setLength(length)
def getWidth(self):
return self.width
def setWidth(self, width):
if (width <= 0):
width = 5
else:
width = self.width
def getLength(self):
return self.length
def setLength(self, length):
if (length <= 0):
length = 10
else:
length = self.length
class Rectangle(Shapes):
def __init__(self, area, perimeter):
Shapes.__init__(self, length, width)
def getArea(length, width):
return length * width
def getPerimeter(length, width):
return (length * 2) + (width * 2)
def getStats(self):
print("Area: {}".format(self.getArea()))
print("Perimeter: {}".format(self.getPerimeter()))
print("Length: {}".format(self.getLength()))
print("Width: {}".format(self.getWidth()))
def main():
print("Rectangle a: ")
a = Rectangle(5, 7)
print("Area: {}".format(a.area))
print("Perimeter: {}".format(a.perimeter))
print(" ")
print("Rectangle b: ")
b = Rectangle()
b.width = 10
b.height = 20
print(b.getStats())
這裏是殼牌正在做什麼,如果你想看看: http://imgur.com/DxyUZyY
什麼我做錯了,我該如何糾正呢?
這是行不通的: 高清__init __(自我,面積,周長): 形狀.__的init __(自我,長度,寬度) –