|
|
发表于 2019-11-3 10:45:50
|
显示全部楼层
- def isnumber(s):
- if s.count('.') == 1:
- list1 = s.split('.')
- if list1[0].isdigit() == True and list1[1].isdigit() == True:
- return True
- else:
- return False
- if s.count('.') == 0:
- if s.isdigit() == True:
- return True
- else:
- return False
- else:
- return False
-
- def func(s:str):
- if s.startswith('-') and (s.endswith('j') or s.endswith('J')):
- if isnumber(s[1:-1]) == True:
- return True
- elif s[1:-1].count('+') == 1:
- list1 = s[1:-1].split('+')
- if len(list1) != 2:
- return False
- for each in list1:
- if isnumber(each) == False:
- return False
- return True
- elif s[1:-1].count('-') == 1:
- list1 = s[1:-1].split('-')
- if len(list1) != 2:
- return False
- for each in list1:
- if isnumber(each) == False:
- return False
- return True
- else:
- return False
- elif isnumber(s[0]) == True and (s.endswith('j') or s.endswith('J')):
- if s[0:-1].count('+') == 1:
- list1 = s[0:-1].split('+')
- if len(list1) != 2:
- return False
- for each in list1:
- if isnumber(each) == False:
- return False
- return True
- elif s[0:-1].count('-') == 1:
- list1 = s[0:-1].split('-')
- if len(list1) != 2:
- return False
- for each in list1:
- if isnumber(each) == False:
- return False
- return True
- elif isnumber(s[0:-1]) == True:
- return True
- else:
- return False
- else:
- return False
复制代码 |
|