"""练习判断一个小数1、判断是否合法2、合法需要有一个小数点3、小数点左边必须是个整数,右边必须是个正整数"""def xiaoshu(s): xiaoshu_new=str(s) if xiaoshu_new.count(".") ==1: left,right = xiaoshu_new.split(".") if left.isdigit() and right.isdigit(): print(1111) return True elif left.startswith('-') and left.count('-') == 1 and right.isdigit(): lleft = left.split('-')[-1] if lleft.isdigit(): return True return Falsea = xiaoshu(-.1)print(a)
好文要顶
转载于:https://www.cnblogs.com/fandonghua/p/11589138.html
相关资源:判断字符串是否有小数的特征,并且能否转换成小数