# L-16 MCS 275 Wed 20 Feb 2008 : reccharcnt.py

# Write a recursive Python function CharCount
# which takes on input a string s and a character c.  
# The function returns the number of times the 
# character c occurs in the string s.

def CharCount(s,c):
   """
   Returns the number of times the 
   character c occurs in the string s.
   """
   if s == '':
      return 0
   elif s[0] == c:
      return 1 + CharCount(s[1:len(s)],c)
   else:
      return CharCount(s[1:len(s)],c)

def main():
   """
   Prompts the user for a string and
   a character and calls CharCount.
   """
   s = raw_input('Give a string : ')
   c = raw_input('Give a character : ')
   n = CharCount(s,c)
   print '#occurrences of %s in %s : %d' \
     % (s,c,n)

main()
