Question

I get an Indentation Error in the else part of this statement. I've checked it for white spaces and can't make any sense out of the error.

if cur_state == 'NICHTGEN':
    cur_state = 'GEN'
elif cur_state == 'GEN' and chance_num > trans_genZuGen:
    cur_state = 'NICHTGEN'
else:
    cur_state = 'GEN'

The exact error is

    else: 
        ^ 
IndentationError: unindent does not match any outer indentation level
Was it helpful?

Solution

First - you are probably mixing spaces and tabs.

Second - this logic can be reduced to

if cur_state == 'GEN' and chance_num > trans_genZuGen:
    cur_state = 'NICHTGEN'
else:
    cur_state = 'GEN'

or even

cur_state = 'NICHTGEN' if cur_state == 'GEN' and chance_num > trans_genZuGen else 'GEN'

(although the first is definitely more readable.)

OTHER TIPS

Make sure you're not using whitespace and tabulation for indentation in the same time.

Also see: Are there any pitfalls with using whitespace in Python?

Let Idle handle the spacing. Use the "End" key, the "Del" key, and the "Return" key on each line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top