Merge branch 'master' of code.ungleich.ch:ungleich-public/ungleich-learning-circle
This commit is contained in:
commit
1cf7d5c81f
5 changed files with 141 additions and 0 deletions
19
kjg/python-the-hard-way/e28.py
Normal file
19
kjg/python-the-hard-way/e28.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#True and True -> True
|
||||||
|
#False and True -> False
|
||||||
|
#1 == 1 and 2 == 1 -> False
|
||||||
|
#"test" == "test" -> True
|
||||||
|
#1 == 1 or 2 != 1 -> True
|
||||||
|
#True and 1 == 1 -> True
|
||||||
|
#False and 0 != 0 -> False
|
||||||
|
#True or 1 == 1 -> True
|
||||||
|
#"test" == "testing" -> False
|
||||||
|
#1 != 0 and 2 == 1 -> False
|
||||||
|
#"test" != "testing" -> True
|
||||||
|
#"test" == 1 -> False
|
||||||
|
#not (True and False) -> True
|
||||||
|
#not(1 == 1 and 0 != 1) -> False
|
||||||
|
#not (10 == 1 or 1000 == 1000) -> False
|
||||||
|
#not(1 != 10 or 3 == 4) -> False
|
||||||
|
#not ("testing" == "testing" and "Zed" == "Cool Guy") -> True
|
||||||
|
#1 == 1 and (not("testing" == 1 or 1 == 0)) -> True
|
||||||
|
#"chunky" == "bacon" and (not (3 == 4 or 3 == 3)) -> Fasle
|
35
kjg/python-the-hard-way/e29.py
Normal file
35
kjg/python-the-hard-way/e29.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
people = 21
|
||||||
|
cats = 33
|
||||||
|
dogs = 14
|
||||||
|
|
||||||
|
|
||||||
|
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!")
|
||||||
|
|
||||||
|
if people != dogs:
|
||||||
|
print("People are not dogs.")
|
||||||
|
|
||||||
|
|
||||||
|
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.")
|
||||||
|
|
28
kjg/python-the-hard-way/e30.py
Normal file
28
kjg/python-the-hard-way/e30.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
people = 21
|
||||||
|
cars = 15
|
||||||
|
trucks = 30
|
||||||
|
|
||||||
|
if cars > people: #check cars are bigger than people
|
||||||
|
print("We should take the cars.") #print if cars are bigger than people
|
||||||
|
elif cars < people: #check cars are smaller than people
|
||||||
|
print("We should not take the cars.") #print if cars are smaller than people
|
||||||
|
else:
|
||||||
|
print("We can't decide.") #print if cars are same with people
|
||||||
|
|
||||||
|
|
||||||
|
if trucks > cars: #check trucks are bigger than cars
|
||||||
|
print("That's too many trucks.") #print if trucks are bigger than cars
|
||||||
|
elif trucks < cars: #check trucks are smaller than cars
|
||||||
|
print("Maybe we could take the trucks.") #print if trucks are smaller than cars
|
||||||
|
else:
|
||||||
|
print("We still can't decide.") #print if trucks are same with cars
|
||||||
|
|
||||||
|
if people > trucks: #check people are bigger than trucks
|
||||||
|
print("Alright, let's just take the trucks.") #print if people are bigger than trucks
|
||||||
|
else:
|
||||||
|
print("Fine, let's stay home then.") #print if people are bigger than trucks
|
||||||
|
|
||||||
|
if cars > people or trucks < cars: #check cars are bigger than people or trucks are smaller than cars
|
||||||
|
print("cars are many") #print if cars are bigger than people or trucks are smaller than cars
|
||||||
|
else:
|
||||||
|
print("trucks or people is bigger") #print not (cars > people or trucks < cars)
|
48
kjg/python-the-hard-way/e31.py
Normal file
48
kjg/python-the-hard-way/e31.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
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!")
|
||||||
|
|
||||||
|
|
||||||
|
if door == "3":
|
||||||
|
print(f"you choose {door}")
|
||||||
|
if int(door) in range(1, 10):
|
||||||
|
print("in 1 between 10")
|
||||||
|
else:
|
||||||
|
print("not in between 10")
|
||||||
|
else:
|
||||||
|
print(f"you choose {door}")
|
||||||
|
|
|
@ -110,3 +110,14 @@ practice function and print
|
||||||
practice import function
|
practice import function
|
||||||
**** ex26
|
**** ex26
|
||||||
practice debug code
|
practice debug code
|
||||||
|
*** Python #4:
|
||||||
|
**** ex27
|
||||||
|
How to use True and Flase
|
||||||
|
**** ex28
|
||||||
|
How to use Boolean
|
||||||
|
**** ex29
|
||||||
|
How to use if-statement
|
||||||
|
**** ex30
|
||||||
|
How to use if-else
|
||||||
|
**** ex31
|
||||||
|
How to use if, elif
|
||||||
|
|
Loading…
Add table
Reference in a new issue