Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: unindent error

  1. #1
    New to the CF scene
    Join Date
    May 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    unindent error

    i get
    "unindent does not match any outer indentation level"
    and i pressed format-> ident region
    and still it gives me that error

    Code:
         class HouseLocation:
            def __init__(self,x,y,street_name):
                 """how to check if its non negative"""
                 """lizrok exception??"""
                 self.x=x  
                 self.y=y
                 if x>39 or x<0 or y<0 or y>39:
                     raise ValueError("invalid x or y value")
                 
                 self.street_name=street_name
    
    
            def print_address(self):
                print self.street_name, ": ",self.x,",",self.y
    
        class Street:
            def __init__(self,street_name,map_symbol,street_ends):
                self.street_name=street_name
                
                self.house_locations={}
                if map_symbol.islower()==False:
                    """ difference between " and '  """
                    raise ValueError("symbol must be a single lowercase letter!")
                else:
                    self.map_symbol=map_symbol
                         
                if street_ends[0][0]>39 or street_ends[0][0]<0:
                    raise ValueError("ends out of range!")
                if street_ends[0][1]>39 or street_ends[0][1]<0:
                    raise ValueError("ends out of range!")
                if street_ends[1][0]>39 or street_ends[1][0]<0:
                    raise ValueError("ends out of range!")
                if street_ends[1][1]>39 or street_ends[1][1]<0:
                    raise ValueError("ends out of range!")
                if street_ends[0][0]==street_ends[0][1] and street_ends[0][1]==street_ends[1][1]:
                    raise ValueError("ends are identifical!")
                
            def valid_house_to_add(self, house):
             
               
               return isBetween(self.street_ends[0], (house.x,house.y), self.street_ends[1]) and self.house_locations.has_key((x,y))
                   
                   
            def add_house(self,house):
                if valid_house_to_add(self, house)==True:
                    self.house_locations= {(house.x,house.y):True}
                else:
                    raise ValueError("invaid adrees for this street")
                
                   
                                   
        class City:
            def  __init__(self,city_name):
                 self.streets=[]
                 self.city_name=city_name
    
            def valid_street_to_add(self,test_street):
                """can i write only self in for"""
                for i in range(len(self.streets)):
                    if self.streets[i].map_symbol==test_street.map_symbol or self.streets[i].street_name==test_street.stree_name :
                        return False
                    else:
                        return True
    
             def add_street(self,street):
                 if self.valid_street_to_add(street)==True:
                    self.streets.append(street)
         
                     
             def print_map(self):
                 map = []
          for i in range(1,40): """empty 2d array"""
              map.append(['_'])
              for j in range(1,40):
                     map[i].append('_')
    
    
          for i in self.streets:
               for j in self.streets[i].house_locations(j):
                     map[self.streets[i].house_locations(j).x],[self.streets[i].house_locations(j).y]=self.streets[i].map_symbol
    
    
    
    def isBetween(a, b, c):
                crossproduct = (c[1] - a[1]) * (b[0] - a[0]) - (c[0] - a[0]) * (b[1] - a[1])
                if abs(crossproduct) != 0  : return False
    
                dotproduct = (c[0] - a[0]) * (b[0] - a[0]) + (c[1] - a[1])*(b[1] - a[1])
                if dotproduct < 0 : return False
    
                squaredlengthba = (b[0] - a[0])*(b[0] - a[0]) + (b[1] - a[1])*(b[1] - a[1])
                if dotproduct > squaredlengthba: return False
                return True

  2. #2
    New Coder
    Join Date
    Nov 2016
    Location
    South Africa, Cape Town
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    It's difficult to say. Is the code you've pasted exactly like that in your file? If so the class constructors indentation level isn't top level. Also in class "City" the for loops are outside of the function print_map.
    The function isBetween has too many levels of indentation and the if statements aren't indented.

  3. #3
    New Coder
    Join Date
    Nov 2016
    Location
    South Africa, Cape Town
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    This gives me no errors:

    Code:
    class HouseLocation:
        def __init__(self,x,y,street_name):
            """how to check if its non negative"""
            """lizrok exception??"""
            self.x=x  
            self.y=y
            if x>39 or x<0 or y<0 or y>39:
                raise ValueError("invalid x or y value")
                 
            self.street_name=street_name
    
    
        def print_address(self):
            print self.street_name, ": ",self.x,",",self.y
    
    class Street:
        def __init__(self,street_name,map_symbol,street_ends):
            self.street_name=street_name
                
            self.house_locations={}
            if map_symbol.islower()==False:
                """ difference between " and '  """
                raise ValueError("symbol must be a single lowercase letter!")
            else:
                self.map_symbol=map_symbol
                     
            if street_ends[0][0]>39 or street_ends[0][0]<0:
                raise ValueError("ends out of range!")
            if street_ends[0][1]>39 or street_ends[0][1]<0:
                raise ValueError("ends out of range!")
            if street_ends[1][0]>39 or street_ends[1][0]<0:
                raise ValueError("ends out of range!")
            if street_ends[1][1]>39 or street_ends[1][1]<0:
                raise ValueError("ends out of range!")
            if street_ends[0][0]==street_ends[0][1] and street_ends[0][1]==street_ends[1][1]:
                raise ValueError("ends are identifical!")
                
        def valid_house_to_add(self, house):
            return isBetween(self.street_ends[0], (house.x,house.y), self.street_ends[1]) and self.house_locations.has_key((x,y))
                   
                   
        def add_house(self,house):
            if valid_house_to_add(self, house)==True:
                self.house_locations= {(house.x,house.y):True}
            else:
                raise ValueError("invaid adrees for this street")
                
                   
                                   
    class City:
        def  __init__(self,city_name):
             self.streets=[]
             self.city_name=city_name
    
        def valid_street_to_add(self,test_street):
            """can i write only self in for"""
            for i in range(len(self.streets)):
                if self.streets[i].map_symbol==test_street.map_symbol or self.streets[i].street_name==test_street.stree_name :
                    return False
                else:
                    return True
    
        def add_street(self,street):
             if self.valid_street_to_add(street)==True:
                self.streets.append(street)
     
    
        def print_map(self):
            map = []
            for i in range(1,40): """empty 2d array"""
            map.append(['_'])
            for j in range(1,40):
                map[i].append('_')
    
    
            for i in self.streets:
                for j in self.streets[i].house_locations(j):
                    map[self.streets[i].house_locations(j).x],[self.streets[i].house_locations(j).y]=self.streets[i].map_symbol
    
    
    
        def isBetween(a, b, c):
            crossproduct = (c[1] - a[1]) * (b[0] - a[0]) - (c[0] - a[0]) * (b[1] - a[1])
            if abs(crossproduct) != 0  : return False
            dotproduct = (c[0] - a[0]) * (b[0] - a[0]) + (c[1] - a[1])*(b[1] - a[1])
            if dotproduct < 0 : return False
            squaredlengthba = (b[0] - a[0])*(b[0] - a[0]) + (b[1] - a[1])*(b[1] - a[1])
            if dotproduct > squaredlengthba: return False
            return True

    Note: This code is 'hella messy...


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •