Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # #!/usr/bin/python
- #
- # By dvdjaco
- # Exercise 6.3
- #
- # Encapsulate this code in a function named count, and generalize it so that it accepts the string and the letter as arguments.
- # count the number of times that 'letter' occurs in 'string' and return that number
- def count(string, letter):
- c = 0
- for l in string:
- if l == letter:
- c = c +1
- return c
- # test it
- lc = count('test string', 't')
- print lc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement