From 3562ed8e4129517db80a2829f2e22a7ad8717ba9 Mon Sep 17 00:00:00 2001 From: Ganome Date: Tue, 20 Apr 2021 16:47:17 +0000 Subject: [PATCH] Exercise 26-33 --- python/lp3thw/Exercise27/README.md | 4 ++++ python/lp3thw/Exercise28/README.md | 3 +++ python/lp3thw/Exercise29/ex29.py | 27 +++++++++++++++++++++++++++ python/lp3thw/Exercise30/ex30.py | 22 ++++++++++++++++++++++ python/lp3thw/Exercise31/ex31.py | 28 ++++++++++++++++++++++++++++ python/lp3thw/Exercise32/ex32.py | 30 ++++++++++++++++++++++++++++++ python/lp3thw/Exercise33/ex33.py | 17 +++++++++++++++++ python/lp3thw/Exercise34/ex34.py | 0 8 files changed, 131 insertions(+) create mode 100644 python/lp3thw/Exercise27/README.md create mode 100644 python/lp3thw/Exercise28/README.md create mode 100644 python/lp3thw/Exercise29/ex29.py create mode 100644 python/lp3thw/Exercise30/ex30.py create mode 100644 python/lp3thw/Exercise31/ex31.py create mode 100644 python/lp3thw/Exercise32/ex32.py create mode 100755 python/lp3thw/Exercise33/ex33.py create mode 100644 python/lp3thw/Exercise34/ex34.py diff --git a/python/lp3thw/Exercise27/README.md b/python/lp3thw/Exercise27/README.md new file mode 100644 index 0000000..76a2d30 --- /dev/null +++ b/python/lp3thw/Exercise27/README.md @@ -0,0 +1,4 @@ +This chapter covers truth tables. We are asked or instructed to make a set of flash card truth tables. + +No actualy script for this exercise, + diff --git a/python/lp3thw/Exercise28/README.md b/python/lp3thw/Exercise28/README.md new file mode 100644 index 0000000..fbdbe89 --- /dev/null +++ b/python/lp3thw/Exercise28/README.md @@ -0,0 +1,3 @@ +This lesson was testing Boolean login in the python interpreter. + +There was no script associated with this lesson. \ No newline at end of file diff --git a/python/lp3thw/Exercise29/ex29.py b/python/lp3thw/Exercise29/ex29.py new file mode 100644 index 0000000..139f65c --- /dev/null +++ b/python/lp3thw/Exercise29/ex29.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +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!") +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/python/lp3thw/Exercise30/ex30.py b/python/lp3thw/Exercise30/ex30.py new file mode 100644 index 0000000..eab6e27 --- /dev/null +++ b/python/lp3thw/Exercise30/ex30.py @@ -0,0 +1,22 @@ +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 manty 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.") \ No newline at end of file diff --git a/python/lp3thw/Exercise31/ex31.py b/python/lp3thw/Exercise31/ex31.py new file mode 100644 index 0000000..4d7db73 --- /dev/null +++ b/python/lp3thw/Exercise31/ex31.py @@ -0,0 +1,28 @@ +print("""You enter a dark room with two doors. +Do you go through door #1 or door #2?""") + +door = input(" Decision > ") + +if door == "1": + print("There's a giant bear here eating a chese cake.") + print("What do you do?") + print("1.\tTake the cake.\n2.\tScream at the bear") + + bear = input(" Decision > ") + + if bear == "1": + print("The bear eats your face off. Good Job!") + elif bear == "2": + print("The bear eats your legs off! Good luck getting away!") + else: + print(f"Well, doing {bear} is probably better") +elif door == "2": + print("You stare into the endless abyss at Cthulhu's retina") + print("1.\tBlueberries\n2.\tYellow jacket clothespins.\n3.\tUnderstanding revolvers yelling melodies.") + + insanity = input(" Decision > ") + + if insanity == "1" or insanity == "2": + print("Your body survives powered by a mind of jello.\nGOOD JOB!!!") + else: + print("You stumble around and fall on a knife and die.\nWONDERFUL!!") diff --git a/python/lp3thw/Exercise32/ex32.py b/python/lp3thw/Exercise32/ex32.py new file mode 100644 index 0000000..aaab673 --- /dev/null +++ b/python/lp3thw/Exercise32/ex32.py @@ -0,0 +1,30 @@ +theCount = [1, 2, 3, 4, 5] +fruits = ["Apples", "Oranges", "Pears", "Apricots"] +change = [1, "pennies", 2, "dimes", 3, "quarters"] + +#this for loop will iterate though a list +for number in theCount: + print(f"this is count {number}") + +#This for loop does the same as above, with a different variable name +for fruit in fruits: + print(f"This is a(n): {fruit}") + +#also we can go through mixed lists too +#notice we have to use {} since we dont know what's in it - copied from book and doesn't make sense +for i in change: + print(f"I got {i}") + +#we can also build lists, first start with an empty one +elements = [] + +#then use the range function to do 0 to 5 counts +for i in range(0, 6): #NOTE that the last digit in range is EXCLUSIVE. not Inclusive. Meaning it is not included! + print(f"Adding {i} to the list") + #append is a list function + elements.append(i) + +#now we can print them out too +for i in elements: + print(f"Element was: {i}") + diff --git a/python/lp3thw/Exercise33/ex33.py b/python/lp3thw/Exercise33/ex33.py new file mode 100755 index 0000000..1460350 --- /dev/null +++ b/python/lp3thw/Exercise33/ex33.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 +i = 0 +numbers = [] + +while i <= 5: + print(f"At the top i is {i}") + numbers.append(i) + + i += 1 + print(f"Numbers now: {numbers}") + print(f"At the bottom is: {i}") + + +print("The numbers: ") + +for num in numbers: + print(num) \ No newline at end of file diff --git a/python/lp3thw/Exercise34/ex34.py b/python/lp3thw/Exercise34/ex34.py new file mode 100644 index 0000000..e69de29