如何阅读键盘输入? [英] How to read keyboard-input?
本文介绍了如何阅读键盘输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用python从键盘读取数据
I would like to read data from the keyboard in python
我尝试:
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.
你知道为什么吗?
推荐答案
尝试
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"
这篇关于如何阅读键盘输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文