Created
May 15, 2020 08:12
-
-
Save ohr-emet/6d660a9f0fe12a259f33e12cfc774397 to your computer and use it in GitHub Desktop.
py4e - Ch 6 Strings: Ex3 [def function to count]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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