From 9a223eba2440b6b146b9c6617e45264d8a19ae5d Mon Sep 17 00:00:00 2001 From: Doug Lasa <27441098+DFYT42@users.noreply.github.com> Date: Sun, 29 Jul 2018 15:12:04 -0700 Subject: [PATCH 1/2] Update Python_Open-Read-&-Count-Text-File.py Added definitions, notes, and section to count all characters in a text, (without spaces). --- Python_Open-Read-&-Count-Text-File.py | 32 ++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Python_Open-Read-&-Count-Text-File.py b/Python_Open-Read-&-Count-Text-File.py index 6177b5f..6179300 100644 --- a/Python_Open-Read-&-Count-Text-File.py +++ b/Python_Open-Read-&-Count-Text-File.py @@ -2,17 +2,33 @@ ##Given a file path: ##read file, count total words and lines -##open, read, close file -a = open("hello.txt") +##Pulls/Imports + ##open, read, close file +a = open("hello.txt") ##puth path to your text file content = a.read() a.close() -##count words in file and format output with placeholder and word list count -words = content.split() -print("There are {0} words in the file.".format(len(words))) +##Definitions: + ##count words in file and format output with placeholder and word list count +def wordcount(a): + words = content.split() + print("There are {0} words in the file.".format(len(words))) -##count lines in file and format output with placeholder and line list count -num_lines = sum(1 for line in open("hello.txt")) -print("There are {0} lines in the file.".format(num_lines)) + ##count lines in file and format output with placeholder and line list count +def linecount(a): + num_lines = sum(1 for line in open("hello.txt")) + print("There are {0} lines in the file.".format(num_lines)) + ##count characters in file +def count_characters(content): + words = content.split() + counter = 0 + for i in words: + counter = counter + len(i) + print("There are {0} characters in the file.".format(counter)) + +##Calls +wordcount(a) +linecount(a) +count_characters(content) From 9be156ea33de72100131df147236e6d9173e47fa Mon Sep 17 00:00:00 2001 From: Doug Lasa <27441098+DFYT42@users.noreply.github.com> Date: Sun, 29 Jul 2018 15:14:49 -0700 Subject: [PATCH 2/2] Update Python_Open-Read-&-Count-Text-File.py Accidentally updated original. Replaced update with original.