Advertisement
dvdjaco

6.3

Feb 18th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. # #!/usr/bin/python
  2. #
  3. # By dvdjaco
  4. # Exercise 6.3
  5. #
  6. # Encapsulate this code in a function named count, and generalize it so that it accepts the string and the letter as arguments.
  7.  
  8. # count the number of times that 'letter' occurs in 'string' and return that number
  9. def count(string, letter):
  10.     c = 0
  11.     for l in string:
  12.         if l == letter:
  13.             c = c +1
  14.     return c
  15.    
  16. # test it
  17. lc = count('test string', 't')
  18. print lc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement