-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (34 loc) · 1.12 KB
/
main.py
File metadata and controls
42 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from stats import *
import sys
def main():
# path="books/frankenstein.txt"
if len(sys.argv) != 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
path = sys.argv[1]
text=get_book_text(path)
count_of_words = num_words(text)
count_letters = count_unique(text)
sorted_chars = sort_letters(count_letters)
#print (get_book_text(path))
# print(f" Found {count_of_words} total words")
# print(f" Unique {count_letters} letters")
print("============ BOOKBOT ============")
print(f"Analyzing book found at {path}...")
print("----------- Word Count ----------")
print(f"Found {count_of_words} total words")
print("--------- Character Count -------")
for item in sorted_chars:
print(f"{item['char']}: {item['num']}")
print("============= END ===============")
def get_book_text(path_to_file):
print (text)
def get_book_text(path_to_file):
with open(path_to_file) as f:
file_contents = f.read()
return file_contents
#def num_words(text):
# words = text.split()
# return len(words)
if __name__ == "__main__":
main()