写一个函数的程序,判断是否是浮点数

算法:

0.先把小数,转换成str类型,才能调以下方法判断;

1.先判断数值中,是否有小数点,用count计数器;

2.是小数的,需要以‘.’分割小数;

3.小数点左侧若是负数,需要用startswith方法,以什么字符开始;

4.小数点第二位判断是否是数字,小数点右侧,也需要判断是否是一个数字;

def is_float(count):
    s = str(count)
    if s.count('.')==1:
        right,left=s.split('.')
        if right.isdigit() and left.isdigit():
            print('正整数')
            return True
        elif right.startswith('-') and right[1:].isdigit and 
            left.isdigit():
            print('﹣小数')
            return True
    print('不合法')
    return False
原文地址:https://www.cnblogs.com/lily-20141202/p/10055526.html