Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Type 'q' to quit")
- while True:
- filename = input("Enter file name: ")
- if filename == 'q':
- break
- else:
- try:
- with open(filename, encoding="utf8") as f:
- contents = f.read()
- except FileNotFoundError:
- print("File not found.")
- else:
- while True:
- word = input("Enter the word you want to count: ")
- word_count = contents.lower().count(word.lower())
- if word == 'q':
- raise SystemExit
- else:
- with open(filename, encoding="utf8") as f:
- contents = f.read()
- word_count = contents.lower().count(word.lower())
- print("The word '" + word.lower() + "' appears " +
- str(word_count) + " times on this file.\n")
- print("Type 'c' to change the file or 'a' to search " +
- "for another word")
- command = input("Input the command: ")
- print()
- if command == 'c':
- break
- elif command == 'a':
- continue
- elif command == 'q':
- raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement