How to read keyboard-input?

tranen picture tranen · Mar 23, 2011 · Viewed 481.2k times · Source

I would like to read data from the keyboard in python

I try this:

nb = input('Choose a number')
print ('Number%s \n' % (nb))

But it doesn't work, neither with eclipse nor in the terminal, it's always stop of the question. I can type a number but after nothing happen.

Do you know why?

Answer

sharpner picture sharpner · Mar 23, 2011

try

raw_input('Enter your input:')  # If you use Python 2
input('Enter your input:')      # If you use Python 3

and if you want to have a numeric value just convert it:

try:
    mode=int(raw_input('Input:'))
except ValueError:
    print "Not a number"