diff --git a/sami/learn-python-the-hard-way/ex15_sample.txt b/sami/learn-python-the-hard-way/ex15_sample.txt new file mode 100644 index 0000000..ff0a270 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex15_sample.txt @@ -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. diff --git a/sami/learn-python-the-hard-way/ex18.py b/sami/learn-python-the-hard-way/ex18.py index b9617a4..222a91e 100644 --- a/sami/learn-python-the-hard-way/ex18.py +++ b/sami/learn-python-the-hard-way/ex18.py @@ -1,22 +1,20 @@ # this one is like your scripts with argv def print_two(*args): -arg1, arg2 = args -print(f"arg1: {arg1}, arg2: {arg2}") + arg1, arg2 = args + print(f"arg1: {arg1}, arg2: {arg2}") # ok, that *args is actually pointless, we can just do this def print_two_again(arg1, arg2): - -print(f"arg1: {arg1}, arg2: {arg2}") + print(f"arg1: {arg1}, arg2: {arg2}") # this just takes one argument def print_one(arg1): - -print(f"arg1: {arg1}") + print(f"arg1: {arg1}") # this one takes no arguments def print_none(): + print("I got nothin'.") -print("I got nothin'.") print_two("Zed","Shaw") diff --git a/sami/learn-python-the-hard-way/ex19.py b/sami/learn-python-the-hard-way/ex19.py index a8f60d6..dd121ae 100644 --- a/sami/learn-python-the-hard-way/ex19.py +++ b/sami/learn-python-the-hard-way/ex19.py @@ -1,8 +1,8 @@ def cheese_and_crackers(cheese_count, boxes_of_crackers): -print(f"You have {cheese_count} cheeses!") -print(f"You have {boxes_of_crackers} boxes of crackers!") -print("Man that's enough for a party!") -print("Get a blanket.\n") + print(f"You have {cheese_count} cheeses!") + print(f"You have {boxes_of_crackers} boxes of crackers!") + print("Man that's enough for a party!") + print("Get a blanket.\n") print("We can just give the function numbers directly:") diff --git a/sami/learn-python-the-hard-way/ex20.py b/sami/learn-python-the-hard-way/ex20.py index 2e02b87..91ae9dc 100644 --- a/sami/learn-python-the-hard-way/ex20.py +++ b/sami/learn-python-the-hard-way/ex20.py @@ -6,17 +6,17 @@ script, input_file = argv def print_all(f): -print(f.read()) + print(f.read()) def rewind(f): -f.seek(0) + f.seek(0) def print_a_line(line_count, f): -print(line_count, f.readline()) + print(line_count, f.readline()) current_file = open(input_file) diff --git a/sami/learn-python-the-hard-way/ex21.py b/sami/learn-python-the-hard-way/ex21.py index fffb76a..9187f72 100644 --- a/sami/learn-python-the-hard-way/ex21.py +++ b/sami/learn-python-the-hard-way/ex21.py @@ -1,21 +1,21 @@ def add(a, b): -print(f"ADDING {a} + {b}") -return a + b + print(f"ADDING {a} + {b}") + return a + b def subtract(a, b): -print(f"SUBTRACTING {a} - {b}") -return a - b + print(f"SUBTRACTING {a} - {b}") + return a - b def multiply(a, b): -print(f"MULTIPLYING {a} * {b}") -return a * b + print(f"MULTIPLYING {a} * {b}") + return a * b def divide(a, b): -print(f"DIVIDING {a} / {b}") -return a / b + print(f"DIVIDING {a} / {b}") + return a / b print("Let's do some math with just functions!") diff --git a/sami/learn-python-the-hard-way/ex25.py b/sami/learn-python-the-hard-way/ex25.py new file mode 100644 index 0000000..3c5f122 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex25.py @@ -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) +