# 有效数字

<p><strong>有效数字</strong>（按顺序）可以分成以下几个部分：</p><ol>	<li>一个 <strong>小数</strong> 或者 <strong>整数</strong></li>	<li>（可选）一个 <code>'e'</code> 或 <code>'E'</code> ，后面跟着一个 <strong>整数</strong></li></ol><p><strong>小数</strong>（按顺序）可以分成以下几个部分：</p><ol>	<li>（可选）一个符号字符（<code>'+'</code> 或 <code>'-'</code>）</li>	<li>下述格式之一：	<ol>		<li>至少一位数字，后面跟着一个点 <code>'.'</code></li>		<li>至少一位数字，后面跟着一个点 <code>'.'</code> ，后面再跟着至少一位数字</li>		<li>一个点 <code>'.'</code> ，后面跟着至少一位数字</li>	</ol>	</li></ol><p><strong>整数</strong>（按顺序）可以分成以下几个部分：</p><ol>	<li>（可选）一个符号字符（<code>'+'</code> 或 <code>'-'</code>）</li>	<li>至少一位数字</li></ol><p>部分有效数字列举如下：</p><ul>	<li><code>["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"]</code></li></ul><p>部分无效数字列举如下：</p><ul>	<li><code>["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"]</code></li></ul><p>给你一个字符串 <code>s</code> ，如果 <code>s</code> 是一个 <strong>有效数字</strong> ，请返回 <code>true</code> 。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>s = "0"<strong><br />输出：</strong>true</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>s = "e"<strong><br />输出：</strong>false</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>s = "."<strong><br />输出：</strong>false</pre><p><strong>示例 4：</strong></p><pre><strong>输入：</strong>s = ".1"<strong><br />输出：</strong>true</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>1 <= s.length <= 20</code></li>	<li><code>s</code> 仅含英文字母（大写和小写），数字（<code>0-9</code>），加号 <code>'+'</code> ，减号 <code>'-'</code> ，或者点 <code>'.'</code> 。</li></ul>

以下程序实现了这一功能，请你填补空白处内容：

```python
class Solution(object):
	def isNumber(self, s):
		s = s.strip()
		ls, pos = len(s), 0
		if ls == 0:
			return False
		if s[pos] == '+' or s[pos] == '-':
			pos += 1
		isNumeric = False
		while pos < ls and s[pos].isdigit():
			pos += 1
			isNumeric = True
		_____________________________;
		elif pos < ls and s[pos] == 'e' and isNumeric:
			isNumeric = False
			pos += 1
			if pos < ls and (s[pos] == '+' or s[pos] == '-'):
				pos += 1
			while pos < ls and s[pos].isdigit():
				pos += 1
				isNumeric = True
		if pos == ls and isNumeric:
			return True
		return False
# %%
s = Solution()
print(s.isNumber(s = "0"))
```

## template

```python
class Solution(object):
	def isNumber(self, s):
		s = s.strip()
		ls, pos = len(s), 0
		if ls == 0:
			return False
		if s[pos] == '+' or s[pos] == '-':
			pos += 1
		isNumeric = False
		while pos < ls and s[pos].isdigit():
			pos += 1
			isNumeric = True
		if pos < ls and s[pos] == '.':
			pos += 1
			while pos < ls and s[pos].isdigit():
				pos += 1
				isNumeric = True
		elif pos < ls and s[pos] == 'e' and isNumeric:
			isNumeric = False
			pos += 1
			if pos < ls and (s[pos] == '+' or s[pos] == '-'):
				pos += 1
			while pos < ls and s[pos].isdigit():
				pos += 1
				isNumeric = True
		if pos == ls and isNumeric:
			return True
		return False
# %%
s = Solution()
print(s.isNumber(s = "0"))
```

## 答案

```python
if pos < ls and s[pos] == '.':
	pos += 1
	while pos < ls and s[pos].isdigit():
		pos += 1
		isNumeric = True
```

## 选项

### A

```python
if pos < ls and s[pos] == '.':
	pos += 1
	while pos < ls:
		pos += 1
		isNumeric = True
```

### B

```python
if pos < ls and s[pos] == '.':
	pos += 1
	while pos > ls:
		pos += 1
		isNumeric = True
```

### C

```python
if pos < ls and s[pos] == '.':
	pos += 1
	while pos > ls and s[pos].isdigit():
		pos += 1
		isNumeric = True
```