Wednesday 15 January 2014

python - Wrong arguments on random.uniform() -



python - Wrong arguments on random.uniform() -

help me, because cant find fault code following:

def getrandomposition(self): """ homecoming random position within room. returns: position object. """ homecoming position(random.uniform(0,self.width),random.uniform(0,self.height))

debugger output:

room.getrandomposition() traceback (most recent phone call last): file "<stdin>", line 1, in <module> file "ps2a.py", line 145, in getrandomposition homecoming position(random.uniform(0,self.width),random.uniform(0,self.height)) typeerror: random() takes no arguments (2 given)

ps:position initializer of form position(x,y) ideas? random.uniform takes 2 arguments documentation

the actual debugger output (pdb):

>>> room=ps2a.rectangularroom( ... 3,3) >>> room.getrandomposition() traceback (most recent phone call last): file "<stdin>", line 1, in <module> file "ps2a.py", line 145, in getrandomposition typeerror: random() takes no arguments (2 given) >>> random.random() traceback (most recent phone call last): file "<stdin>", line 1, in <module> nameerror: name 'random' not defined >>> import random >>> random.uniform(1,3) 2.5039752079488458 >>> room.getrandomposition() traceback (most recent phone call last): file "<stdin>", line 1, in <module> file "ps2a.py", line 145, in getrandomposition homecoming position(random.uniform(0,self.width),random.uniform(0,self.height)) typeerror: random() takes no arguments (2 given) >>> import pdb >>> pdb.run("room.getrandomposition()") > <string>(1)<module>() (pdb) s --call-- > /home/kostas/pythonprojects/l4p5/problemset2/ps2a.py(139)getrandomposition () -> def getrandomposition(self): (pdb) s > /home/kostas/pythonprojects/l4p5/problemset2/ps2a.py(145)getrandomposition() -> homecoming position(random.uniform(0,self.width),random.uniform(0,self.height)) (pdb) p self.width 3 (pdb) p self.height 3 (pdb) s typeerror: 'random() takes no arguments (2 given)' > /home/kostas/pythonprojects/l4p5/problemset2/ps2a.py(145)getrandomposition() -> homecoming position(random.uniform(0,self.width),random.uniform(0,self.height)) (pdb)

the position class, asked:

class position(object): """ position represents location in two-dimensional room. """ def __init__(self, x, y): """ initializes position coordinates (x, y). """ self.x = x self.y = y def getx(self): homecoming self.x def gety(self): homecoming self.y def getnewposition(self, angle, speed): """ computes , returns new position after single clock-tick has passed, object current position, , specified angle , speed. not test whether returned position fits within room. angle: number representing angle in degrees, 0 <= angle < 360 speed: positive float representing speed returns: position object representing new position. """ old_x, old_y = self.getx(), self.gety() angle = float(angle) # compute alter in position delta_y = speed * math.cos(math.radians(angle)) delta_x = speed * math.sin(math.radians(angle)) # add together existing position new_x = old_x + delta_x new_y = old_y + delta_y homecoming position(new_x, new_y) def __str__(self): homecoming "(%0.2f, %0.2f)" % (self.x, self.y)

python

No comments:

Post a Comment