day4_生成小数的程序

def is_float(s):
s = str(s).strip()
if s.count('.') == 1:
left, right = s.split('.')
if left.isdigit() and right.isdigit(): # 正小数
return True
# 负小数
elif left.startswith('-') and left.count('-') == 1 and\
left.split('-')[-1].isdigit() and right.isdigit():
return True
return False


print(is_float('-.1'))
print(is_float('5.1'))
print(is_float('5.q'))
print(is_float('5.q.1'))
print(is_float('-5.1'))
print(is_float('--5.1'))
print(is_float('-a.1'))
print(is_float('.1'))
print(is_float('a.1'))
print(is_float('a12'))
print(is_float('2..22-5.6'))
posted @ 2018-03-02 13:50  laosun0204  阅读(123)  评论(0编辑  收藏  举报