# 写一个函数,校验字符串是否为合法的小数
# 需求分析:正小数,负小数都是小数
# 1、判断小数点的个数=1,
# 2、小数点左边是整数,小数点右边也是整数,需要用小数点分割。如果是负小数左边需要有负号
import math
def check_float(s):
s=str(s)
if s.count('.')==1:
s_list = s.split('.')
left = s_list[0]
right = s_list[1]
if left.isdigit() and right.isdigit():
return True
elif left.startswith('-') and left.count('-')==1:
if left.split('-')[-1].isdigit() and right.isdigit():
return True
return False
print(check_float('-a'))
print(check_float('a.a'))
print(check_float('1.6'))
print(check_float('-4.78798797979'))
print(check_float('999999.8888888'))
print(check_float(0.000000009))
print(check_float('9aa99.8888888'))
print(check_float('-.8888888'))
print(check_float(-.5))#代码自动转成 -0.5 所以返回True
print(check_float('-98ssss888.9999'))
print(check_float(999))
print(check_float(math.pi))