zoukankan      html  css  js  c++  java
  • 笨办法35分支和函数

    代码的顺序改了一下,另外,将某处的dead改成了print,自我感觉更合理一些哈哈哈哈或

     1 from sys import exit
     2 
     3 def start():
     4     print("You are in a dark room.")
     5     print("There is a door to your right and left.")
     6     print("Which one do you take?")
     7     next = input(">")
     8     if next == "left":
     9         bear_room()
    10     elif next == "right":
    11         cthulhu_room()
    12     else:
    13         dead("You stumble around the room until you starve.")
    14 
    15 def bear_room():
    16     print("There is a bear here.")
    17     print("The bear has a bunch of honey.")
    18     print("The fat bear is in front of another door.")
    19     print("How are you going to move the bear?")
    20     bear_moved = False
    21     while True:
    22         choice = input(">")
    23         if choice == "take honey":
    24             dead("The bear looks at you then slaps your face off.")
    25         elif choice == "taunt bear" and not bear_moved:
    26             print("The bear has moved from the door. You can go through it now.")
    27             bear_moved = True
    28         elif choice == "taunt bear" and bear_moved:
    29             dead("The bear gets pissed off and chews your leg off.")
    30         elif choice == "open door" and bear_moved:
    31             gold_room()
    32         else:
    33             print("I got no idea what that means.")
    34 
    35 def gold_room():
    36     print("This room is full of gold. How much do you take?")
    37     choice = input(">")
    38     if "0" in choice or "1" in choice:
    39         how_much = int(choice)
    40     else:
    41         how_much = int(choice)
    42         print("Man, learn to type a number.")
    43     if how_much < 50:
    44         print("Nice, you're not greedy, you win!")
    45         exit(0)
    46     else:
    47         dead("You greedy bastard!")
    48 
    49 def cthulhu_room():
    50     print("Here you see the great evil Cthulhu.")
    51     print("He, it, whatever stares at you and you go insane.")
    52     print("Do you flee for your life or eat your head?")
    53     next = input(">")
    54     if "flee" in next:
    55         start()
    56     elif "head" in next:
    57         dead("Well that was tasty!")
    58     else:
    59         cthulhu_room()
    60 
    61 def dead(why):
    62     print(why, "Good job!")
    63     exit(0)
    64 
    65 start()
  • 相关阅读:
    MFC中控制Tips的显示
    VC++6.0/MFC 自定义edit 限制输入内容 响应复制粘贴全选剪切的功能
    VC++6.0/MFC中如何限制Edit控件输入 例子,只能输入0和1
    Windows安装配置php+memcached的方法
    mrg_myIsam分表引擎用法
    用PHP做服务器接口客户端用http协议POST访问安全性一般怎么做
    PHP慢脚本日志和Mysql的慢查询日志(转)
    nginx 配置优化的几个参数
    static详解
    Redis命令总结
  • 原文地址:https://www.cnblogs.com/p36606jp/p/8195599.html
Copyright © 2011-2022 走看看