Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #program by David Weinberger
- ###############Functions###############
- def countLetterFileName(character,file):
- #returns value in for main function
- finalvalue = countLetterOpenFile(character, open(file))
- return finalvalue
- def countLetterOpenFile(c, file):
- #Opens file
- value = 0
- for line in file:
- line = line.strip()
- d = countLetterword(c, line)
- value +=d
- return value
- def countLetterword(c, line):
- #Counts number of times a character shows up
- value = 0
- for char in line:
- if char == c:
- value +=1
- return value
- def main():
- #Primary function, takes a letter and counts the number of times it is in a document
- character = input("""Enter a Letter Please: """)
- filename = input("""Enter File Name: """)
- total = countLetterOpenFile(character,filename)
- print("Total count of " , character , " = " , total)
- ###############Calling Functions###############
- main()
- input("press enter to end")
Add Comment
Please, Sign In to add comment