Skip to content

Instantly share code, notes, and snippets.

@ohr-emet
Created May 15, 2020 08:12
Show Gist options
  • Save ohr-emet/6d660a9f0fe12a259f33e12cfc774397 to your computer and use it in GitHub Desktop.
Save ohr-emet/6d660a9f0fe12a259f33e12cfc774397 to your computer and use it in GitHub Desktop.
py4e - Ch 6 Strings: Ex3 [def function to count]
#Exercise 3: Encapsulate this code in a function named count, and generalize it so that it accepts the string and the letter as arguments
def count(word, letter):
count = 0
for character in word:
if character == letter:
count = count + 1
print (count)
inp_word = input('Enter word: ')
inp_lett = input('Enter letter: ')
count(inp_word, inp_lett)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment