Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

There are two problems here:

  1. You forgot to actually invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You need to make GetRandom.ranNumber accept the self self argument that is passed implicitly when you invoke the method:

    def ranNumber(self):
     return random.random()
    

Once you address these issues, the code works as expected:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>

There are two problems here:

  1. You forgot to actually invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You need to make GetRandom.ranNumber accept the self argument that is passed implicitly when you invoke the method:

    def ranNumber(self):
     return random.random()
    

Once you address these issues, the code works as expected:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>

There are two problems here:

  1. You forgot to actually invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You need to make GetRandom.ranNumber accept the self argument that is passed implicitly when you invoke the method:

    def ranNumber(self):
     return random.random()
    

Once you address these issues, the code works as expected:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>
deleted 20 characters in body
Source Link
user2555451
user2555451

There are two problems here:

  1. You forgot to actually invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You forgotneed to make GetRandom.ranNumber accept the selfself argument that is passed implicitly when you invoke the method. You need to define it like so:

    def ranNumber(self):
     return random.random()
    

Once you fixaddress these two problemsissues, the code works fineas expected:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>

There are two problems here:

  1. You forgot to invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You forgot to make GetRandom.ranNumber accept the self argument that is passed implicitly when you invoke the method. You need to define it like so:

    def ranNumber(self):
     return random.random()
    

Once you fix these two problems, the code works fine:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>

There are two problems here:

  1. You forgot to actually invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You need to make GetRandom.ranNumber accept the self argument that is passed implicitly when you invoke the method:

    def ranNumber(self):
     return random.random()
    

Once you address these issues, the code works as expected:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>
Post Undeleted by Community Bot
Post Deleted by Community Bot
Source Link
user2555451
user2555451

There are two problems here:

  1. You forgot to invoke GetRandom.ranNumber. Add () after it to do this:

    bnum = b.ranNumber()
    
  2. You forgot to make GetRandom.ranNumber accept the self argument that is passed implicitly when you invoke the method. You need to define it like so:

    def ranNumber(self):
     return random.random()
    

Once you fix these two problems, the code works fine:

>>> import random
>>> class GetRandom:
... def __init__(self):
... self.data = ""
... def ranNumber(self):
... return random.random()
...
>>> b = GetRandom()
>>> bnum = b.ranNumber()
>>> print bnum
0.819458844177
>>>
lang-py

AltStyle によって変換されたページ (->オリジナル) /