Working with classes

laila at bneakiwa.nl laila at bneakiwa.nl
Mon Dec 3 17:47:53 EST 2012


Hello, I've been working on this program for a long time but can't seem to get it to work.. The first array is the input file, then a class, another class and the actual program. Could anyone see what is wrong? I'm sorry if the program doesn't make any sense at all  I'm just starting to learn this..

The exercise wants us to do the following:
5,4 4,5 8,7
Add behind 6,3 3,2 9,6 4,3
Add in front 7,6
Add behind 9,8
Add in front 5,5 7,8 6,5 6,4
These are coordinates in the form(x,y) and the x coordinates need to be raised by 1.

pirateinvoer:
5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4




'''
Created on 2 dec. 2012

@author: Laila
'''
class CoordinateRow():
    def __init__(self) :
        self.coordinate_row = []
        
    def row_even(self,EVEN, rows):
        self.row_even=[rows[row] for row in EVEN]
        return self.row_even

    def row_odd(self,ONEVEN,rows):
        self.row_odd=[rows[row] for row in ONEVEN]
        return self.row_odd

    def rows_front(self,index, row_front):
        self.new_row_front=self.row_even.insert(index,row_front)
        return self.new_row_front

    def rows_back(self,index, row_back):
        self.new_row_back=self.row_odd.append(index,row_back)
        return self.new_row_back



class Coordinaat: 
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
        
        
    def correct_coordinates(self, OPHOGING_X, OPHOGING_Y):
        self.x=self.x + OPHOGING_X
        self.y=self.y + OPHOGING_Y
        return self.y
        return self.x


from coordinaat import Coordinaat
from coordinate_row import CoordinateRow

file_input=file('pirateinvoer','r')
all_coordinates=file_input.read()
EVEN=range(0,4,2)
ONEVEN=range(1,5,2)
OPHOGING_X=1
OPHOGING_Y=0

def make_coordinate_row(all_coordinate_rows):
    for coordinate_rows in all_coordinate_rows:
        coordinate_rows=coordinate_rows.split()
        
        make_x_y(coordinate_rows)
        
def make_x_y(coordinate_rows):
    for coordinate_row in coordinate_rows:
        x_y=coordinate_row.split(',')
        return Coordinaat (x_y[0],x_y[1])

def make_route(coordinate_rows):
    result=[]
    new_row=row.coordinate_rows.row_even(EVEN, coordinate_rows)
    result+=new_row
    
    new_row=row.coordinate_rows.row_oneven(ONEVEN, coordinate_rows)
    result+=new_row
    
    print result
    
all_coordinate_rows = all_coordinates.strip().split('=')
make_coordinate_row(all_coordinate_rows)
for coordinates in all_coordinate_rows:
    row = CoordinateRow()
    print row
    
    
    

        

        



More information about the Python-list mailing list