Advertisement
J2112O

Letter Counter

Sep 7th, 2015
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. # looping_counting.py
  2.  
  3. def count_letters(word,letter):
  4.     count = 0
  5.     if letter not in word:
  6.         print("That letter is not in the word in question.")
  7.         raw_input("Press the Enter key to quit the program.")
  8.     else:
  9.         for char in word:
  10.             if char == letter:
  11.                 count += 1
  12.                 times = count                                
  13.                 print("The letter %s, is in the word %s, %d time(s).") % (letter,
  14.             word, times)
  15.                
  16. def main():
  17.     word = raw_input("Enter a word. ")
  18.     letter = raw_input("Which letter did you want to see how many times it is"\
  19.     +" present in the word? ")
  20.     count_letters(word,letter)
  21.                
  22.  
  23. if __name__ == "__main__":
  24.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement