<p>如果我只是在这里阅读我的<code>sum_digits</code>函数,在我的头脑中它是有意义的,但它似乎产生了错误的结果。有小费吗?</p>
<pre><code>def is_a_digit(s):
''' (str) -> bool
Precondition: len(s) == 1
Return True iff s is a string containing a single digit character (between
'0' and '9' inclusive).
>>> is_a_digit('7')
True
>>> is_a_digit('b')
False
'''
return '0' <= s and s <= '9'
def sum_digits(digit):
b = 0
for a in digit:
if is_a_digit(a) == True:
b = int(a)
b += 1
return b
</code></pre>
<p>对于函数<code>sum_digits</code>,如果我输入<code>sum_digits('hihello153john')</code>,它应该产生<code>9</code></p>