Reputation:
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()'
Upvotes: 0
Views: 608
Reputation: 5774
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
Upvotes: 1