Skip to content Skip to sidebar Skip to footer

Python Shell Shows No Error But Program Doesn't Run

I wrote this program to learn the basics of OOP. When I run this program from IDLE in the Python Shell it doesn't show any errors but also doesn't print anything... I'm not sure ho

Solution 1:

You never call the main function. Unlike in C, where main function would automatically execute, in python, you have to explicitly call it; main doesn't hold any special significance and is just another function in python.

So at the end of your code, write:

main()

Once you run that, you will see errors like @Eric pointed in his comments, and many more.


There are many things wrong with your current code, here is a list of a few of them:

  1. object.__init__(self) doesn't do anything
  2. self.setWidth(width) calls the method, but the setWidth method tries to set to a variable that hasn't been declared yet.

    • So this needs to be corrected to

      def setWidth(self, width):
          if (width <=0):
              width = 5else:
              width = width # and not self.width
  3. The above is true for setLength as well.

  4. Since you are using these methods to set and get values, you should look into using @property.
  5. Shapes.__init__(self, length, width) is not the correct call.
    • You need to look into super
    • length, width are not defined here.

Post a Comment for "Python Shell Shows No Error But Program Doesn't Run"