《笨方法学Python》加分题35
sys.exit 用于结束程序 2 from sys import exit 3 4 # 进入黄金房间后的逻辑 5 def gold_room(): 6 print("This room is full of gold. How much do you take?") 7 8 choice = input("> ") 9 # 如果输入不包含 0 或 1 则死 10 if "0" in choice or "1" in choice: 11 how_much = int(choice) 12 else: 13 dead("Man, learn to type a number.") 14 15 # 如果输入的数字大于等于 50 则死 16 if how_much < 50: 17 print("Nice, you're not greedy, you win!") 18 exit(0) 19 else: 20 dead("You greedy basterd!") 21 22 # 实现熊房间的逻辑 23 def bear_room(): 24 print("There is a bear here.") 25 print("The bear has a bunch of honey.") 26 print("The fat bear is in front of another door.") 27 print("How are you going to move the bear?") 28 bear_moved = False 29 30 # 如果熊离开后直接开门就用不到 while 循环了. 31 while True: 32 # print(">>> bear_moved1 = ", bear_moved) 33 choice = input("> ") 34 35 if choice == "take honey": 36 # print(">>> bear_moved2 = ", bear_moved) 37 dead("The bear looks at you then slaps your face off.") 38 elif choice == "taunt bear" and not bear_moved: 39 # print(">>> bear_moved3 = ", bear_moved) 40 print("The bear has moved from the door.") 41 print("You can go through it now.") 42 bear_moved = True 43 elif choice == "taunt bear" and bear_moved: 44 # print(">>> bear_moved4 = ", bear_moved) 45 dead("The bear gets pissed off and chews your legs off.") 46 elif choice == "open door" and bear_moved: 47 # print(">>> bear_moved5 = ", bear_moved) 48 gold_room() 49 else: 50 print("I go no idea what that means.") 51 52 # 恶魔房逻辑 53 def cthulhu_room(): 54 print("Here you see the great evil Cthulhu.") 55 print("He, it, whatever stares at you and you go insane.") 56 print("Do you flee for your life or eat your head?") 57 58 choice = input("> ") 59 60 # 二选一,否则恶魔放循环 61 if "flee" in choice: 62 start() 63 elif "head" in choice: 64 dead("Well that was tasty!") 65 else: 66 cthulhu_room() 67 68 # 惨死函数 69 def dead(why): 70 print(why, "Good job!") 71 exit(0) 72 73 # 启动函数 74 def start(): 75 print("You are in a dark room.") 76 print("There is a door to your right and left.") 77 print("Which one do you take?") 78 79 choice = input("> ") 80 81 if choice == "left": 82 bear_room() 83 elif choice == "right": 84 cthulhu_room() 85 else: 86 dead("You stumble around the room until you starve.") 87 88 # 开始游戏 89 start()
运行结果
posted on 2019-03-18 18:04 阿加西的python之旅 阅读(487) 评论(0) 编辑 收藏 举报