美文网首页
习题35的附加练习4的简化代码

习题35的附加练习4的简化代码

作者: 吴黄龙本人 | 来源:发表于2018-03-09 14:57 被阅读25次
    from  sys import exit
    def gold_room():
           one()
    
            next  = raw_input(">")
    
            if  next.isdigit:
                 how_much  =  int(next)
           if how_much  < 50:
               two()
                exit(0)
            else:
                   dead("You  greedy  bastard!")
    
    def bear_room():
           three()
    
           next  =  raw_input(">")
    
            if  next  ==  "1":
                 dead("The  bear looks  at  you  then  slaps  your  face  off.")
              elif  next  ==  "2":
                     four()
    
               next =  raw_input(">")
    
               if  next  == "1":
                     dead("The  bear  looks  at  you  then  slaps  your  face  off.")
                 elif  next == "3":
                        dead("The bear  get  pissed off and chews  your leg off.")
                   elif  next  ==  "4":
                          gold_room()
                    else:
                          five()
    
    
    def  cthulhu_room():
             six()
    
              next  =  raw_input(">")
    
              if  next  ==  "5":
                    start()
                elif  next  ==  "6":
                       dead("Well that  was  tasty!")
                 else:
                     cthulhu_room()
    
    
    def  dead(why):
             print  why, "Good job!"
              exit(0)
    
    def  start():
            eight()
    
             next  = raw_input(">")
    
              if  next   ==  "7":
                   bear_room()
               elif  next  ==  "8":
                      cthulhu_room()
                else:
                       dead("You  stumble around the room  until you starve.")
    
    
    def  one():
           print  "This  room is  full of  gold.How  much  do  you take?"
    
    def  two():
            print  "Nice, you're not  greedy, you win!"
    
    def  three():
            print  "There is a bear here."
            print  "The bear has a bunch of honey."
            print  "The fat bear is in front of another door."
            print  "How are you going to move the bear?"
            print  "1.take honey"
            print  "2.taunt bear"
    
    def four():
           print "The bear has moved from  the door.You can go through it now."
            print  "1.take honey"
            print  "3.taunt  bear"
            print  "4.open door"
    
    def  five():
           print  "I  got  no  idea  what  that  means."
    
    def  six():
            print  "Here  you  see the great  evil  Cthulhu."
             print  "He, it, whatever stares at you and you go insane."
             print " Do  you  flee for  you  life  or  eat  your  head?"
              print  "5.flee"
              print  "6.head"
    
    def  eight():
           print  "You  are in a dark  room."
           print  "There  is  a  door  to  your  right  and  left."
            print  "which  one  do  you  take?"
            print  "7.left"
            print  "8.right"
    
    
    
    start()
    

    在上一篇文章少写了一个,我开始是start()在def one():前面,在powershell上提示出错,后来把start()放在def eight()后面,正常运行。

    相关文章

      网友评论

          本文标题:习题35的附加练习4的简化代码

          本文链接:https://www.haomeiwen.com/subject/xmjyfftx.html