判断输入的字符是不是数字

判断输入是数字,还是字符串

 方法一:

a = input("请输入一个要判断的字符: ")
m = n = 0
for i in a:
    m += 1
    if i in ['0','1','2','3','4','5','6','7','8','9']:
        n += 1
if m == n:
    print("您输入的是数字:", a)
else:
    print("您输入的是字符串:", a)
    
        

 

 方法二:

myInput = input("请输入一个要判断的字符: ")
isStr = False
for i in myInput:
    if i in ['0','1','2','3','4','5','6','7','8','9']:
        continue
    isStr = True
if isStr:
    print("您输入的是字符串:", myInput)
else:
    print("您输入的是:数字", myInput)

 

posted @ 2017-08-20 01:32  bingxingc  阅读(3063)  评论(0编辑  收藏  举报