From 9b7a30153d0f3b9abe276b904853a13386e28cb1 Mon Sep 17 00:00:00 2001 From: Ganome Date: Tue, 20 Apr 2021 00:32:13 +0000 Subject: [PATCH] Exercise 26 lp2thw - Corrected all errors. Script compiles and runs no issues --- python/lp3thw/Exercise25/ex25.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 python/lp3thw/Exercise25/ex25.py diff --git a/python/lp3thw/Exercise25/ex25.py b/python/lp3thw/Exercise25/ex25.py new file mode 100644 index 0000000..269f732 --- /dev/null +++ b/python/lp3thw/Exercise25/ex25.py @@ -0,0 +1,35 @@ +def breakWords(stuff): + """This function will break up words for us.""" + words = stuff.split(' ') + return words + +def sortWords(words): + """Sort words.""" + return sorted(words) + +def printFirstWord(words): + """Print first word after popping it off.""" + word = words.pop(0) + print(word) + +def printLastWord(words): + """Prints the last word after popping it off.""" + word = words.pop(-1) + print(word) + +def sortSentence(sentence): + """Takes in a full sentence and returns the sorted words.""" + words = breakWords(sentence) + return sortWords(words) + +def printFirstAndLast(sentence): + """Printe the first and last word of a sentence""" + words = breakWords(sentence) + printFirstWord(words) + printLastWord(words) + +def printFirstAndLastSorted(sentence): + """Sorts the words then prints the first and last one.""" + words = sortSentence(sentence) + printFirstWord(words) + printLastWord(words)