0

In the following, why it is not printing results even though I don't see any errors:

class Test(object):
 def __init__(self, x, y):
 self.x = x
 self.y = y
 def printing(self):
 var = self.x + self.y
 print(" RESULT= %i " % var)
if __name__ == '__main__':
 Test().printing(10, 20)
asked Mar 30, 2016 at 19:00
4
  • 1
    Your first order of business is to figure out why you're not seeing any errors; that code should definitely generate one. Commented Mar 30, 2016 at 19:02
  • Yes I just noticed my mistake. I just don't know why I could not spot it. I apologize Commented Mar 30, 2016 at 19:05
  • Wait, when you said "I don't see any errors", did you mean "I think my code is right even though there is an error", or do you mean "it generated no errors"? I thought you meant the second and that something was wrong with your Python setup. If you see that your code is generating an exception, you should always copy and paste it into your questions Commented Mar 30, 2016 at 19:16
  • I meant it generated no errors. Commented Mar 30, 2016 at 21:31

1 Answer 1

3
if __name__ == '__main__':
 Test().printing(10, 20)

Should be

Test(10, 20).printing()

You have mistake in instance initialization.

answered Mar 30, 2016 at 19:01
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.