0

Whats wrong in this code? its showing

File "KeybordControleTest1.py", line 13
    elif c == curses.KEY_UP:
                       ^

IndentationError: unindent does not match any outer indentation level

I am unsure how to solv this error

import curses

screen = curses.initsrc()
curses.noecho()
curses.cbreak()
screen.keypad(True)

try:
    while True:
     c = screen.getch()
     if c == ord('q'):
          break
    elif c == curses.KEY_UP:
       print "UP"
    elif c == curses.KEY_DOWN:
           print "DOWN"
    elif c == curses.KEY_RIGHT:
           print "RIGHT"
    elif c == curses.KEY_LEFT:
           print "LEFT"
    elif char == 10:
        print "STOP"
finally:
    curses.nocbreak(); screen.keypad(0); curses.echo()
    curses.endwin()'
JoSSte
  • 2,953
  • 6
  • 34
  • 54
  • 1
    In python indentation matters. Notice the `if` statement and `elif` statement should be in the same indentation – DanielM Jan 25 '19 at 17:29

1 Answers1

1

yes the indentation is entirely wrong in your program. You need to define clear indents of one tab or 4 spaces per layer, and maintain consistency...

import curses

screen = curses.initsrc()
curses.noecho()
curses.cbreak()
screen.keypad(True)

try:
    while True:
        c = screen.getch()
        if c == ord('q'):
            break
        elif c == curses.KEY_UP:
            print "UP"
        elif c == curses.KEY_DOWN:
            print "DOWN"
        elif c == curses.KEY_RIGHT:
            print "RIGHT"
        elif c == curses.KEY_LEFT:
            print "LEFT"
        elif char == 10:
            print "STOP"
finally:
    curses.nocbreak(); screen.keypad(0); curses.echo()
    curses.endwin()'

You can see here I have indented it such that it is very apparent what logic follows what statements

Reedinationer
  • 5,661
  • 1
  • 12
  • 33