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) + diff --git a/sami/learn-python-the-hard-way/ex28.py b/sami/learn-python-the-hard-way/ex28.py new file mode 100644 index 0000000..2b47619 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex28.py @@ -0,0 +1,27 @@ +3 == 3 and (not ("testing" == "testing" or "Python" == "Fun")) +False + +3 == 3 and (not ("testing" == "testing" or False)) +False + +3 == 3 and (not (True or "Python" == "Fun")) +False + +3 == 3 and (not (True or False)) +False + +3 == 3 and (not ("True")) +False + +3 == 3 and False +False + +True and False +False + + + +True and False or False and True + False or False and True + False and False + False diff --git a/sami/learn-python-the-hard-way/ex29.py b/sami/learn-python-the-hard-way/ex29.py new file mode 100644 index 0000000..6cd602d --- /dev/null +++ b/sami/learn-python-the-hard-way/ex29.py @@ -0,0 +1,41 @@ +people = 20 +cats = 30 +dogs = 15 + + + + +if people < cats: + print("Too many cats! The world is doomed!") + + + +if people > cats: + print("Not many cats! The world is saved!") + + + +if people < dogs: + print("The world is drooled on!") + + + +if people > dogs: + print("The world is dry!") + + + +dogs += 5 + + + +if people >= dogs: + print("People are greater than or equal to dogs.") + + +if people <= dogs: + print("People are less than or equal to dogs.") + + +if people == dogs: + print("People are dogs.") diff --git a/sami/learn-python-the-hard-way/ex30.py b/sami/learn-python-the-hard-way/ex30.py new file mode 100644 index 0000000..3a470f1 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex30.py @@ -0,0 +1,27 @@ +people = 30 +cars = 40 +trucks = 15 + + + +if cars > people: + print("We should take the cars.") +elif cars < people: + print("We should not take the cars.") +else: + print("We can't decide.") + + + +if trucks > cars: + print("That's too many trucks.") +elif trucks < cars: + print("Maybe we could take the trucks.") +else: + print("We still can't decide.") + + +if people > trucks: + print("Alright, let's just take the trucks.") +else: + print("Fine, let's stay home then.") diff --git a/sami/learn-python-the-hard-way/ex31.py b/sami/learn-python-the-hard-way/ex31.py new file mode 100644 index 0000000..34bbad2 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex31.py @@ -0,0 +1,43 @@ +print("""You enter a dark room with two doors. +Do you go through door #1 or door #2?""") + + +door = input("> ") + + +if door == "1": + print("There's a giant bear here eating a cheese cake.") + print("What do you do?") + print("1. Take the cake.") + print("2. Scream at the bear.") + + bear = input("> ") + + if bear == "1": + print("The bear eats your face off. Good job!") + elif bear == "2": + print("The bear eats your legs off. Good job!") + else: + print(f"Well, doing {bear} is probably better.") + print("Bear runs away.") + +elif door == "2": + print("You stare into the endless abyss at Cthulhu's retina.") + print("1. Blueberries.") + print("2. Yellow jacket clothespins.") + print("3. Understanding revolvers yelling melodies.") + + + insanity = input("> ") + + + if insanity == "1" or insanity == "2": + print("Your body survives powered by a mind of jello.") + print("Good job!") + else: + print("The insanity rots your eyes into a pool of muck.") + print("Good job!") + + +else: + print("You stumble around and fall on a knife and die. Good job!")