Merge remote-tracking branch 'sami/master'

This commit is contained in:
Nico Schottelius 2020-05-27 17:02:19 +02:00
commit 5427dd5adf
10 changed files with 197 additions and 22 deletions

View 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.

View File

@ -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")

View File

@ -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:")

View File

@ -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)

View File

@ -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!")

View 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)

View File

@ -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

View File

@ -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.")

View File

@ -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.")

View File

@ -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!")