Exercise 26 lp2thw - Corrected all errors. Script compiles and runs no issues
This commit is contained in:
parent
e51066f7be
commit
9b7a30153d
35
python/lp3thw/Exercise25/ex25.py
Normal file
35
python/lp3thw/Exercise25/ex25.py
Normal file
@ -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)
|
||||||
Loading…
x
Reference in New Issue
Block a user