Skip to content

Instantly share code, notes, and snippets.

@RobColeman
Last active August 29, 2015 14:21
Show Gist options
  • Save RobColeman/2babd0fad3d7f01f3d7e to your computer and use it in GitHub Desktop.
Save RobColeman/2babd0fad3d7f01f3d7e to your computer and use it in GitHub Desktop.
for x in "asdfasdfas2343asdf232dfasdf": print(x.isdigit())
def how_many_numbers_in_the_word(word):
counter = 0
for x in word:
if x.isdigit():
counter = counter + 1
return counter
how_many_numbers_in_the_word("this_has_no_number")
how_many_numbers_in_the_word("this_has_1_number")
how_many_numbers_in_the_word("th1s_has_2_numbers")
how_many_numbers_in_the_word("th1s_has_2_numb3rs")
# if you wanted to NOT return the count, and only print
def how_many_numbers_in_the_word_print(word):
counter = 0
for x in word:
if x.isdigit():
counter = counter + 1
print counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment