Ex34:
有序数列的顺序,从0开始。
Ex35:
这部分代码很多,类似于之前的ex14的zork游戏。需要注意 while True 和 exit(0)
while True:
choice = input(">")
if choice == "take honey":
dead("The bear looks at you then slaps your face off.")
elif choice == "taunt bear" and not bear_moved:
print("The bear has moved from the door.")
print("You can go through it now.")
bear_moved = True
elif choice == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your leg off.")
elif choice == "open door" and bear_moved:
gold_room()
else:
print("I got no idea what that means.")
while True makes an infinite loop
def dead(why):
print(why, "Good job!")
exit(0)
Why did you write while True? That makes an infinite loop.
What does exit(0) do? On many operating systems a program can abort with exit(0), and the number passed in will indicate an error or not. If you do exit(1) then it will be an error, but exit(0) will be a good exit. The reason it’s backward from normal Boolean logic (with 0==False) is that you can use different numbers to indicate different error results. You can do exit(100) for a
different error result than exit(2) or exit(1).
Ex36:
一些debug和design原则
Ex37:
很多很多keywords 和 运算符 和转移字符等,要好好学习。