1

My code is not running although everything is properly indented and I have been using Python for a while now, so I am no longer in the world of programming. I couldn't find the solution.

def revisedRussianRoulette(doors):
    counter = 0
    for i in range(0, len(doors), 2):
        i = int(i)
        if doors[i] == 1 & counter == 0:
            counter += 1
        elif doors[i] == 1 & counter == 1:
            doors[i] = 0
            doors[i-2] = 0
            doors[i+2] = 0
        elif doors[i] == 0 & counter == 1:
            doors[i-2] = 0
    return doors


n = int(input().strip())
doors = list(map(int, input().strip().split(' ')))
result = revisedRussianRoulette(doors)
print (" ".join(map(str, result)))

The thing I want to do with this code does not matter. I just want to ask if the syntax is correct because I am getting the following error.

C:\Users\lenovo\Desktop\Practice Files>2nd_answer_week_of_code_36.py
  File "C:\Users\lenovo\Desktop\PracticeFiles\2nd_answer_week_of_code_36.py", line 13
return doors
           ^
IndentationError: unindent does not match any outer indentation level

Please, could anyone tell me the solution fast?

EDIT:

The solution provided by Vikas was accurate, although there were no differences between his and my code.

oATOMo
  • 13
  • 1
  • 4
  • do indent in `elif` both `elif` should be inside for loop – Vikas Periyadath Feb 06 '18 at 12:06
  • also, the `counter += 1` line is not indented 1 level extra from the preceding `if` – Cristian Lupascu Feb 06 '18 at 12:07
  • I have updated the question. This is my current code. That was poor formatting earlier. First question of mine on Stack Overflow. – oATOMo Feb 06 '18 at 12:26
  • Possible duplicate of [IndentationError: unindent does not match any outer indentation level](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – Guy Feb 06 '18 at 13:06

2 Answers2

1

Do indenation like this :

def revisedRussianRoulette(doors):
    counter = 0
    for i in range(0, len(doors), 2):
        i = int(i)
        if doors[i] == 1 & counter == 0:
            counter += 1
        elif doors[i] == 1 & counter == 1:
            doors[i] = 0
            doors[i-2] = 0
            doors[i+2] = 0
        elif doors[i] == 0 & counter == 1:
            doors[i-2] = 0
    return doors
Vikas Periyadath
  • 3,088
  • 1
  • 21
  • 33
0
def revisedRussianRoulette(doors):
    counter = 0
    for i in range(0, len(doors), 2):
        i = int(i)
        condition_one = doors[i] == 1 & counter == 0
        condition_two = doors[i] == 1 & counter == 1
        condition_three = doors[i] == 0 & counter == 1
        if condition_one:
            counter += 1
        elif condition_two:
            doors[i] = 0
            doors[i-2] = 0
            doors[i+2] = 0
        elif condition_three:
            doors[i-2] = 0
        return doors

n = int(input().strip())
doors = list(map(int, input().strip().split()))
result = revisedRussianRoulette(doors)
print (" ".join(map(str, result)))
Veera Balla Deva
  • 790
  • 6
  • 19