# ex28 布尔运算的练习
print(1, True and True)
print(2, False and True)
print(3, 1 == 1 and 2 == 1)
print(4, "test" == "test")
print(5, 1 == 1 and 2 != 1)
print(6, True and 1 == 1)
print(7, False and 0 != 0)
print(8, True or 1 == 1)
print(9, "test" == "testing")
print(10, 1 != 0 and 2 == 1)
print(11, "test" != "testing")
print(12, "test" == 1)
print(13, not (False and True))
print(14, not (1 == 1 and 0 != 1))
print(15, not (10 == 1 or 1000 == 1000))
print(16, not (10 != 1 or 3 == 4))
print(17, not ("test" == "testing" and "Zed" == "Cool Guy"))
print(18, 1 == 1 and not ("testing" == 1 or 1 == 0))
print(19, "chunky" == "bacon" and (not (3 == 4 or 3 == 3)))
print(20, 3 == 3 and (not ("testing" == "testing" or "Python" == "Fun")))
"""
为什么
"test" and "test" 返回 "test"
"test" and "testing" 返回 "testing"
1 and 1 返回 1
False and 1 返回 False
False and 0 返回 False
0 and False 返回 0
1 and False 返回 False
True and 0 返回 0
True and 1 返回 1
1 and True 返回 True
"""
# ex29
# if语句的简单使用
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.")
# ex30
# if和else语句
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.")
"""
如果多个elif语句块均为正确,python只会执行第一个正确的语句块
"""
# ex31
# 这是一个if的嵌套使用例子
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("1.XXX")
print("2.XXX")
print("3.XXX")
insanity = input("> ")
if insanity == "1" or insanity == "2":
print("Your input 1 or 2")
else:
print("Your input is not 1 or 2")
else:
print("This is door")