From ea7b80cdcd20b7d8179024357caf393abb22a139 Mon Sep 17 00:00:00 2001 From: Bluejustice397 Date: Fri, 17 Jan 2025 13:26:52 -0800 Subject: [PATCH 1/2] Added function to handle misentered files --- SentenceLength.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SentenceLength.py b/SentenceLength.py index 4ee13bc..a37d5f1 100644 --- a/SentenceLength.py +++ b/SentenceLength.py @@ -28,6 +28,14 @@ def findAverageSentence(filePath, delimiters, minLength): def main(): userFile = input("Enter the file path to the .txt file you wish to analyze.\n") + isFile = os.path.isfile(userFile) + while isFile != True: + print("Enter a valid file") + userFile = input("Enter the file path to the .txt file you wish to analyze.\n") + isFile = os.path.isfile(userFile) + + + userDelimeters = input("Enter the characters (punctuation) that you want to be sentence delimiters separated by spaces.\n") userDelimeters = userDelimeters.split(" ") minLength = input("Enter the minimum length of a word (must be a positive integer).\n") From 9fa95a95de8ca686ae6ab21f9d3cf66873949210 Mon Sep 17 00:00:00 2001 From: Bluejustice397 Date: Fri, 17 Jan 2025 13:28:54 -0800 Subject: [PATCH 2/2] Added feature and killed Mathew's code --- SentenceLength.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/SentenceLength.py b/SentenceLength.py index a37d5f1..5d5b3db 100644 --- a/SentenceLength.py +++ b/SentenceLength.py @@ -42,14 +42,7 @@ def main(): minLenPro = "" - for i in range(len(minLength)): - # print("1234567890".contains(minLength[i])) - if (minLength[i] in "1234567890") == False: - minLenPro = minLenPro + "" - else: - minLenPro = minLenPro + minLength[i] - - print(minLenPro) + print("The average sentence length is", findAverageSentence(userFile, userDelimeters, minLength))