-3

I am new in python, there is this error in the if else statement "unindent does not match any outer indentation level", can anyone tell me what is the problem with if else statements?

def idfs(graph, start, end,limit):
    # maintain a queue of paths
    count=0
    queue = []

    # push the first path into the queue
    queue.append([start])
    #print queue

    while queue:
        count +=1
        # get the first path from the queue
        path = queue.pop(0)

        # get the last node from the path
        node = path[-1]

        # path found
        if node == end and count==2:
            return path
        elif node!=end and count==2:
            print 'goal not found'
            limit=input('Enter the limit again')
         path=idfs(graph,node,goal,limit)
         return path




        # enumerate all adjacent nodes, construct a new path and push it into the queue
        for adjacent in graph.get(node, []):
            new_path = list(path)
            print new_path
            new_path.append(adjacent)
            print new_path
            queue.append(new_path)
            print queue


# example execution of code
start = input('Enter source node: ')
goal = input('Enter goal node: ')
limit=input('Enter the limit')

print(idfs(graph,start,goal,limit))
halex
  • 16,253
  • 5
  • 58
  • 67
  • Apart from solving indentation You should replace elif with else in this case – sachin saxena May 18 '15 at 08:13
  • possible duplicate of [IndentationError: unindent does not match any outer indentation level](http://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – jeromej May 18 '15 at 08:15

1 Answers1

1

The two lines after elif are misaligned. Depending on whether they belong to while or inside elif, move them either 1 space to the left or 3 spaces to the right to solve the issue.

Vadim Landa
  • 2,784
  • 5
  • 23
  • 33