python-crash-course/Chapter_10/10-10_common_words.py
2025-03-06 00:33:58 +00:00

28 lines
1.1 KiB
Python

# Exercise 10-10 Common Words
# Learning Objective: Take a free ebook and gather data on how many times a word is found within it.
from pathlib import Path
book1 = Path("./Chapter_10/bible.txt")
bible = book1.read_text()
print("\n\nKing James Version Bible Stats:\n")
print(f"THERE: {bible.lower().count('there')}")
print(f"THEM: {bible.lower().count('them')}")
print(f"THE: {bible.lower().count('the')}")
print(f"THE : {bible.lower().count('the ')}")
book2 = Path("./Chapter_10/scientific_american_vol_37.txt")
sciam = book2.read_text()
print("\n\nScientific American, Vol XXXVII STATS:\n")
print(f"THERE: {sciam.lower().count('there')}")
print(f"THEM: {sciam.lower().count('them')}")
print(f"THE: {sciam.lower().count('the')}")
print(f"THE : {sciam.lower().count('the ')}")
book3 = Path("./Chapter_10/the_manufacture_of_paper.txt")
paper = book3.read_text()
print("\n\n THE MANUFACTURE OF PAPER STATS:\n")
print(f"THERE: {paper.lower().count('there')}")
print(f"THEM: {paper.lower().count('them')}")
print(f"THE: {paper.lower().count('the')}")
print(f"THE : {paper.lower().count('the ')}")