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:
object.__init__(self)
doesn't do anythingself.setWidth(width)
calls the method, but thesetWidth
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
The above is true for
setLength
as well.- Since you are using these methods to set and get values, you should look into using
@property
. Shapes.__init__(self, length, width)
is not the correct call.- You need to look into
super
length
,width
are not defined here.
- You need to look into
Post a Comment for "Python Shell Shows No Error But Program Doesn't Run"