Python: why is random.randint(1,100) returning two values?
Question: I'm trying to work through python assignments because I already know java and
C#, and managed to place out of the python class in my college with my AP
Computer Science score.

This is a SetTitle function that I have created. The Write function has
already been implemented in the given class.

    
    
    class HTMLOutputFile:
    
    def SetTitle( title ):
        if not str(title):
            return false
        else:
            Write("<TITLE>",title,"<TITLE>")
            return true
    

This file is calling my SetTitle method to make sure it works properly.

    
    
    from htmloutputfile import *
    import random
    
    MyHTMLOutputFile = HTMLOutputFile()
    
    if MyHTMLOutputFile.SetTitle(random.randint(1,100)):
        print('Error: SetTitle accepted non-string')
        exit(0)
    
    if not MyHTMLOutputFile.SetTitle('My Title'):
        print('Error: SetTitle did not accept string')
        exit(0)
    

But, when I run it, I receive the error

    
    
    if MyHTMLOutputFile.SetTitle(random.randint(1,100)):
    TypeError: SetTitle() takes exactly 1 argument (2 given)
    

Do you guys have any ideas why random.randint(1,100) might be considered as
two arguments instead of 1? I don't need a direct fix if you don't want to
give it to me, but I'd like a point in the right direction.

Thanks.


Answer: change

    
    
    def SetTitle( title ):
    

to

    
    
    def SetTitle(self, title ):
    

Each class method must have the first parameter the instance the method is
called on. It thinks it is two arguments because it automatically passes self
to the function.

[What is the purpose of self in
Python?](http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-
self-in-python)

