I keep getting this error for this code,
" line 44, in <module> robot_1 = Robot('robot_1.txt')TypeError: Robot() takes no arguments"
class Robot: def _init_(self, instruction_file): self.instruction_file =instruction_file self.instruction_list = None
def write_instructions(self): f = open(self.instruction_file,'w') while True: movement_x = input('EnterSide movement, or q to stop:') if movement_x =='q': break movement_y = input('Entervertical movement, or q to quit: ') if movement_y =='q': break f.write(movement_x +'\n') f.write(movement_y +'\n') f.close()
def read_instructions(self): try: f =open(self.instruction_file, 'r') except FileNotFoundError aserror: print(error) else: self.instruction_list =f.readlines() f.close()
def get_location(self): position_x, position_y = 0, 0 distance_x, distance_y = 0, 0 self.read_instructions() if self.instruction_list != None: for data inself.instruction_list: temp =data[:-1] ifself.instruction_list.index(data) % 2 == 0: position_x += float(temp) distance_x += abs(float(temp)) else: position_y += float(temp) distance_y += abs(float(temp)) return position_x, position_y,distance_x, distance_y
robot_1 = Robot('robot_1.txt')robot_1.write_instructions()pos_x, pos_y, dis_x, dis_y = robot_1.get_location()print('The robot is at destination' + str(pos_x) + ',' +str(pos_y))print('The robot have traveled a distance of ' + str(dis_x) +'sideways,' + str(dis_y) + 'vertically')
I keep getting this error for this code, " line 44, in robot_1 = Robot('robot_1.txt') TypeError: Robot() ta
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am