zoukankan      html  css  js  c++  java
  • 《笨方法学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()

    运行结果

  • 相关阅读:
    SQOOP的安装配置_Linux伊甸园开源社区24小时滚动更新开源资讯,全年无休!
    Cloudera's Hadoop Demo VM for CDH4 Cloudera Support
    海量文档查同或聚类问题 Locality Sensitive Hash 算法
    part 1: resemblance with the jaccard coefficient
    计算机科学中最重要的32个算法zz
    详细的tfidf构建过程实例(转)
    2012 Beijing Google Dev FastDay(11/03/2012) 移动新观察
    百度技术沙龙
    Hive官方手册翻译(Getting Started) 实践检验真理 51CTO技术博客
    《周末休闲吧》:教你如何玩车震——车震全程攻略!_周末休闲吧_百度空间
  • 原文地址:https://www.cnblogs.com/python2webdata/p/10553820.html
Copyright © 2011-2022 走看看