1

For instance I would like it so,

x = int(input("Please enter your guess :")
If x = 1:
   Print ("correct")

Although each time i need to press enter, how could I make it so it would read on key press.

I did find getch() although i could not get it to work.

Jack
  • 2,891
  • 11
  • 48
  • 65
  • http://stackoverflow.com/questions/3523174/raw-input-in-python-without-pressing-enter – benst Apr 22 '13 at 11:05
  • I did look through that although i was hoping some one could provide me a example of how to use getch() for my example. – Jack Apr 22 '13 at 11:07
  • http://code.activestate.com/recipes/134892/ - getch()-like unbuffered character reading from stdin on both Windows and Unix (Python recipe) – thavan Apr 22 '13 at 12:03

1 Answers1

1

In Windows you can use msvcrt. On other systems its a bit more difficult, take a look at this recipe: http://code.activestate.com/recipes/134892/

You can use it that way:

getch = _Getch()

print 'Please enter your guess: '
x = getch()

if (int(x) == 1):
    print 'correct'
else:
    print 'wrong'
dersvenhesse
  • 6,276
  • 2
  • 32
  • 53