0
Traceback (most recent call last):
  File "C:\Users\sahib navlani\Desktop\gfh.py", line 107, in <module>
    main()
  File "C:\Users\sahib navlani\Desktop\gfh.py", line 98, in main
    crit2.play()
  File "C:\Users\sahib navlani\Desktop\gfh.py", line 34, in play
    self.play -= play1
TypeError: unsupported operand type(s) for -=: 'instancemethod' and 'int'

I get this error whenever i put this code . I think this due to line self.play -= play

play1 = int(raw_input("Please enter the time for which you want to play = "))
self.play -= play1
2
  • 2
    Maybe you need int(self.play) -= play1. And by the way, can you show your full code? Commented Nov 9, 2015 at 4:46
  • 1
    Please show us the full code of your self.play method, so we can help you. Otherwise we're just guessing at what is wrong. Commented Nov 9, 2015 at 5:27

2 Answers 2

1

It's because self.play is a member method. I think you have done mixing of names of member methods and member names. Give proper names to variables and be clear about the purpose for which you are using it.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes you are right i did the mixing of names.Thanks a lot brother
0

I'm only guessing since you haven't shown us the code that's going wrong, but I think you're using the function name as a return value. This is a bad habit that Visual Basic teaches people -- nearly every other language uses return instead, which is what Python does. In Python, you would use a variable (I like to use result) to calculate what you'll return, then put return result at the end of your function. E.g.,

def addTwoNumbers(one, two):
    # addTwoNumbers = one + two   # Wrong!
    result = one + two
    return result

In a simple function like this, you could just write return one + two, but in more complicated functions, it's useful to use a variable to calculate the result, then return it at the end. So that's what I showed in this example.

Comments

Your Answer

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.