Python – How to read keyboard-input

inputkeyboardpython

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?

Best Answer

Use

input('Enter your input:')

if you use Python 3.

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

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

If you use Python 2, you need to use raw_input instead of input.