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()
  • 相关阅读:
    服务器与本地时间的倒计时
    没有花括号(大括号)的for循环也能正确执行
    js瀑布流效果
    AQS详解(AbstractQueuedSynchronizer)
    SimpleDateFormat的线程安全问题与解决方案
    jvm不打印异常栈
    Java中的序列化Serialable高级详解
    java梳理-序列化与反序列化
    AQS详解
    对ConditionQueue和锁的理解
  • 原文地址:https://www.cnblogs.com/p36606jp/p/8195599.html
Copyright © 2011-2022 走看看