# 关于python多元输入问题(我需要输入数字)

0

str.isdigit函数,其返回值是"True"or"False"，可以判断是否是数字

#coding=utf8

if num.isdigit():
print "OK,This is number."
else:
print "Error,Sorry you enter is not number code."
0

def  isnum(num):
try:
num = int(num) #transfer interget
if num < 0:
print 'the number you input is negative:%d' % num
return True
elif num > 0:
print  'the number you input is positive:%d' % num
return True
else:
print  'the number you input is zero'
return True
except(ValueError):
try:
num = float(num)
print 'the number you input is decimal:%f' % num
return True
except(ValueError):
print "the number you input is not decimal or string:%s" % num
return False
val = raw_input('plezse input you number:')
if isnum(val):
print 'good'
else:
print 'not number string'

0

#### 引用来自“gddyl”的答案

def  isnum(num):
try:
num = int(num) #transfer interget
if num < 0:
print 'the number you input is negative:%d' % num
return True
elif num > 0:
print  'the number you input is positive:%d' % num
return True
else:
print  'the number you input is zero'
return True
except(ValueError):
try:
num = float(num)
print 'the number you input is decimal:%f' % num
return True
except(ValueError):
print "the number you input is not decimal or string:%s" % num
return False
val = raw_input('plezse input you number:')
if isnum(val):
print 'good'
else:
print 'not number string'

en 确实欠考虑