python - Sum the digits of a strings using type(int) -



python - Sum the digits of a strings using type(int) -

i have seen question when googled tried else run programme fails, help me figure out why method wrong.

def sumdigits(s): """assumes s string. if s 'a2b3dc' homecoming 5""" a=0 in string: if type(i) == int: a=a+1 homecoming sumdigits('ab23sdf');

this method homecoming me zero. why?

use isdigit instead.

i.isdigit()

when iterate string string, need check if given chararacter digit.

secondly string variable undefined, should utilize s instead.

python

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -