20170921习题
ex28
#布尔表达式练习
True and True
"test" == "test"
1 == 1 or 2 != 1
True or 1 == 1
"test" == "testing"
1 != 2 and 2 == 1
"test" != "testing"
"test" == 1
not(True and False)
not(1 == 1 and 1 != 0)
not(10 == 1 or 1000 == 1000)
not(1 != 10 or 3 == 4)
not("testing" == "testing" and "zed" == "cool guy")
1 == 1 and ("testing" == 1 or 1 == 0)
"chunky" == "bacon" and not(3 == 4 or 3 == 3)
3 == 3 and not ("testing" == "testing" or "python" == "fun")
#把==或者!=的部分转化成True或者False
#先算()内的部分
#算not的反义部分
#算and或者or部分
#最后都转化成True或者False
----------------------------------------------------------------
ex.29
#如果-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 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
#Else和If,statement-语句
people = 30
cars = 40
buses = 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 buses > cars:
print("that's too many buses.")
elif buses < cars:
print("maybe we could take the buses.")
else:
print("we still can't decide.")
if people > buses:
print("all right,let's take the buses.")
else:
print("fine, let's stay home then.")
-------------------------------------------------
ex31
#做出决定
#if语句嵌套(nested)
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 is a giant bear here eating a cheese cake.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("well,doing %s is probably better. bear runs away." %bear)
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 is survives powered by a mind of jello.good job.")
else:
print("the insanity rots your eyes into a pool of muck.good jobs.")
else:
print("you stumble around and fall on a knife and die.good job.")
--------------------------------------------------------------------------------
2017-09-21 21:57:58