reviewing ex.15 to 26
This commit is contained in:
parent
402d63519d
commit
d270952bf0
6 changed files with 59 additions and 22 deletions
3
sami/learn-python-the-hard-way/ex15_sample.txt
Normal file
3
sami/learn-python-the-hard-way/ex15_sample.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
This is stuff I typed into a file.
|
||||||
|
It is really cool stuff.
|
||||||
|
Lots and lots of fun to have in here.
|
|
@ -5,20 +5,18 @@ print(f"arg1: {arg1}, arg2: {arg2}")
|
||||||
|
|
||||||
# ok, that *args is actually pointless, we can just do this
|
# ok, that *args is actually pointless, we can just do this
|
||||||
def print_two_again(arg1, arg2):
|
def print_two_again(arg1, arg2):
|
||||||
|
|
||||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||||
|
|
||||||
# this just takes one argument
|
# this just takes one argument
|
||||||
def print_one(arg1):
|
def print_one(arg1):
|
||||||
|
|
||||||
print(f"arg1: {arg1}")
|
print(f"arg1: {arg1}")
|
||||||
|
|
||||||
# this one takes no arguments
|
# this one takes no arguments
|
||||||
def print_none():
|
def print_none():
|
||||||
|
|
||||||
print("I got nothin'.")
|
print("I got nothin'.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print_two("Zed","Shaw")
|
print_two("Zed","Shaw")
|
||||||
print_two_again("Zed","Shaw")
|
print_two_again("Zed","Shaw")
|
||||||
print_one("First!")
|
print_one("First!")
|
||||||
|
|
36
sami/learn-python-the-hard-way/ex25.py
Normal file
36
sami/learn-python-the-hard-way/ex25.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
def break_words(stuff):
|
||||||
|
"""This function will break up words for us."""
|
||||||
|
words = stuff.split(' ')
|
||||||
|
return words
|
||||||
|
|
||||||
|
|
||||||
|
def sort_words(words):
|
||||||
|
"""Sorts the words."""
|
||||||
|
return sorted(words)
|
||||||
|
|
||||||
|
|
||||||
|
def print_first_word(words):
|
||||||
|
"""Prints the first word after popping it off."""
|
||||||
|
word = words.pop(0)
|
||||||
|
print(word)
|
||||||
|
|
||||||
|
|
||||||
|
def print_last_word(words):
|
||||||
|
"""Prints the last word after popping it off."""
|
||||||
|
word = words.pop(-1)
|
||||||
|
print(word)
|
||||||
|
|
||||||
|
|
||||||
|
def sort_sentence(sentence):
|
||||||
|
"""Takes in a full sentence and returns the sorted words."""
|
||||||
|
words = break_words(sentence)
|
||||||
|
return sort_words(words)
|
||||||
|
|
||||||
|
|
||||||
|
def print_first_and_last(sentence):
|
||||||
|
"""Prints the first and last words of the sentence."""
|
||||||
|
words = break_words(sentence)
|
||||||
|
print_first_word(words)
|
||||||
|
print_last_word(words)
|
||||||
|
|
Loading…
Add table
Reference in a new issue