Exercise 26-33

This commit is contained in:
Ganome 2021-04-20 16:47:17 +00:00
parent e400aade67
commit 3562ed8e41
8 changed files with 131 additions and 0 deletions

View File

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

View File

@ -0,0 +1,3 @@
This lesson was testing Boolean login in the python interpreter.
There was no script associated with this lesson.

View File

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

View File

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

View File

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

View File

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

View File

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

View File