为什么我的代码不会运行?

时间:2014-03-20 16:13:14

标签: python

Ascii credits - http://www.chris.com/ascii

代码不会在pyscripter中运行,因为某些原因只显示两个V形符号提示请帮我解决?谢谢。此外,如果您认为您发现代码有任何问题(错误)等。随意纠正我或自己纠正,谢谢。

     import random
     import time

    playagain = True
    def intro():



     print('You and your brave behind stare at the large dark forest infront of you.')
     time.sleep(2)
     print()
     print('Instead of ignoring the darkness and spookiness of the forest you decide to enter anyways.')
     time.sleep(2)
     print()
     print('You do not worry because you are a brave archer heralding a bow with deadly tipped arrows.')
     print()
     print('What is your name brave Archer')
     print()
     choice = input()
     print('That is a name which brings fear, ' + choice)
     print()

     def monsters():

    monster = ['''oo88888888boo
            `""88888888888bo
                ""888; `"Y888o
                   Y88;    "Y88.
                    "88.     `88b.    ,
                     `Yb      `888.   :8b
                       Yb    , `888.   88b
                        Y.    ` `"88.  Y8"8.
                         Y. `. b ``8b  :8 Y8.
           ,oooooooo      Yo :.`b`b`8;  8  8b
    ,ood8P""""""""88888oo  8b Y.:b:b:8;,8 ,:8.
,od88888bo  ` ,o.   """888o`8b`8 Y.8.88d8 : 8;
"""""""""""8oo`,. 'oo.   ""888b8b:8db8888 d :8 :;
          d8888boP , "Y88o. ""Y8888888888 8 d8.88
        o""""888888o``o'"88bood8888888888:8,;8888
      o"    ""8888888o."88888888" oooo `888d888:8
     d'    ,o8888888P88od88P""' ,d8888; Y888888:8
   ,8'     ood88888,dP"88       :888888 :88888;d;
   8'  ,o88""8888`8P   `"       888888P  8888d;8;
  d;,o8P" ,d888'oP'             "8888"    d88888boo
  8,88'  ,8888'88                 `' ,o8; "" Y88888888oooo.
 :88'   ,8888'dP,88o    :;          d88P    oooo88d888888888bo.
 `"    ,8888;,;:88888.  d8.        :8P'   ""'          :8888888888ooo
      ,88888 8,88. :88; 88;     ood"                    88888888888P"Y;
     oP d88;d;d888od"Y8  8;     ""                      :8P""Y88PYb8 :
    :P'd888`8'8b  ""Y88. 8'                             `"   `8"  YP 8
   ,P .:Y8Pd8,8Y88o.  :;                                     `"  o8 d;
  ,8'','8888;:8o   """Y8           ooood88888oooo.       o         dP
  8P  ,d88'8;:8"888oooo8;       ,o888888888888888888boo  `Y8oo.   dP
 :8bd88888 8':8ooo.  ""Yb     odP""          """888888888bo8P""'o8"
 """""8888 8 :8888888o. 8oooo888oooooooooo.       Y8888888888oo8"
     d8888 Y :bo     `""""888P"""         ""Ybo.    `"8888888""
    ,8`Y88.: :8"Y88oooooooo88.                `Ybo     Y8"
    dP'd88;:; 8o        `""Y8b                  `"b.   dP
    88`8:8;:; 88888booooood888.                   `8.  8'
   :8P:'Y88:b 8P            `8b                    `8d8'
   88 ',88888 Y8888ooooooP""""Yb                    `"
  ,8; o8888bY;8Yb '         ooo88b
  :8o8":;888'8;88bo,od8` '`'`'  Ybo
  d8"  d;888bP;o'`        ,.:o:'`"P o
  "'   8'8888d8b,;odP8;dP'`    o:;`'8 :o       '
       8 :8P8'88o`8P''    ooo'   ,oo" d8.dboo
      ,8 :`d88b,88od8888P"'   oo""  ,'" dP"88888
      :P  88888;8b 888;   oo8"'   ,P' ,8' d'88"8
      d;,dY88888.Y. Y8888""    odP' ,d" ,d'dP ,P
      8bP' Y8Y888d8o `Y8;  ood8P' ,dP  o8':P  :;
     ,P"   :8YY;88b"b  Y8888P"  o'"  o8P ,P   8  -hrr-
           `8d:`888b`bo `8b  ,o8"  ,dP' ,P   :;
            8;:dP88888Yb  Y888;   d8;  ,P    8
            8;:8 :8888b88. `Y8boo8P'  ,P    :;
            8b8' `88:;Y88"b. `Y888   ,P     8
            88'   Y88':88b."8o `"8b.oP     8'
            "'    :8Y :88888o"8o  :88o.  ,8'
                   8: 88;8Y88b88bod8"Y8oo8P
                   8.d':b8`8:P`"8888o. :8P
                   88'  Yd 88'   `"88888"
                  :8'   `8 dP       """'
                  `'     8o8
                         88''', '''  ___
  `-._~-.                                  / /_ "~o\  :Y
      \  \                                / : \~x.  ` ')
       ]  Y                              /  |  Y< ~-.__j
      /   !                        _.--~T : l  l<  /.-~
     /   /                 ____.--~ .   ` l /~\ \<|Y
    /   /             .-~~"        /| .    ',-~\ \L|
   /   /             /     .^   \ Y~Y \.^>/l_   "--'
  /   Y           .-"(  .  l__  j_j l_/ /~_.-~    .
 Y    l          /    \  )    ~~~." / `/"~ / \.__/l_
 |     \     _.-"      ~-{__     l  :  l._Z~-.___.--~
 |      ~---~           /   ~~"---\_  ' __[>
 l  .                _.^   ___     _>-y~
  \  \     .      .-~   .-~   ~>--"  /
   \  ~---"            /     ./  _.-'
    "-.,_____.,_  _.--~\     _.-~
                ~~     (   _}
                        `. ~(
                          )  \
                         /,`--'~\--''' , '''
                _ ___                /^^\ /^\  /^^\_
    _          _@)@) \            ,,/ '` ~ `'~~ ', `\.
  _/o\_ _ _ _/~`.`...'~\        ./~~..,'`','',.,' '  ~:
 / `,'.~,~.~  .   , . , ~|,   ,/ .,' , ,. .. ,,.   `,  ~\_
( ' _' _ '_` _  '  .    , `\_/ .' ..' '  `  `   `..  `,   \_
 ~V~ V~ V~ V~ ~\ `   ' .  '    , ' .,.,''`.,.''`.,.``. ',   \_
  _/\ /\ /\ /\_/, . ' ,   `_/~\_ .' .,. ,, , _/~\_ `. `. '.,  \_
 < ~ ~ '~`'~'`, .,  .   `_: ::: \_ '      `_/ ::: \_ `.,' . ',  \_
  \ ' `_  '`_    _    ',/ _::_::_ \ _    _/ _::_::_ \   `.,'.,`., \-,-,-,_,_,
   `'~~ `'~~ `'~~ `'~~  \(_)(_)(_)/  `~~' \(_)(_)(_)/ ~'`\_.._,._,'_;_;_;_;_; '''
    ,  '''  |\___/|
            (,\  /,)\
            /     /  \
           (@_^_@)/   \
            W//W_/     \
          (//) |        \
        (/ /) _|_ /   )  \
      (// /) '/,_ _ _/  (~^-.
    (( // )) ,-{        _    `.
   (( /// ))  '/\      /      |
   (( ///))     `.   {       }
    ((/ ))    .----~-.\   \-'
             ///.----..>   \
              ///-._ _  _ _} '''


, '''
            / o       o \
           /   \     /   \
          /     )-"-(     \
         /     ( 6 6 )     \
        /       \ " /       \
       /         )=(         \
      /   o   .--"-"--.   o   \
     /    I  /  -   -  \  I    \
 .--(    (_}y/\       /\y{_)    )--.
(    ".___l\/__\_____/__\/l___,"    )
 \                                 /
  "-._      o O o O o O o      _,-"
      `--Y--.___________.--Y--'
         |==.___________.==| ''']


    print('You walk through the forest slowly...')
    time.sleep(2)
    print('You hear a crack as if a twig broke..')
    time.sleep(2)
    print('The creature leaps out from the shadows!')
    time.sleep(5)
    print()
    print(random.choice(monster))
    print('You must engage the creature!')

     def battle():

    attack = [poison, fire, lightning, ice, greatbow]
    gold = [1,2,3]
    print('You ready your bow as you choose which tipped arrow to use embued with magic..')
    time.sleep(2)
    print('You strung your bow with the ' + random.choice(attack) + ' arrow')
    time.sleep(3)
    print('You take down the foe as he slowly tumbles to the ground!')
    time.sleep(2)
    print('The bigger they are the harder they fall')
    time.sleep(3)
    print('Would you like to enter deeper into the forest or flee while you can, you collected ' + gold + ' gold stacks this time around')
    playagain = input()
    while playagain == 'yes':
    return intro
    return monsters
    return battle
    else: exit()

2 个答案:

答案 0 :(得分:0)

根据需要列出字符串或某些数据类型。换例如

attack = ["poison", "fire", "lightning", "ice", "greatbow"]

其次将int gold更改为str,如下所示:

print('Would you like to enter deeper into the forest or flee while you can, you collected ' + str(gold) + ' gold stacks this time around')

我正在使用python2.7,也将'yes'更改为"yes"

    playagain = raw_input('Choose a number')
    while playagain == "yes":
        return intro
        return monsters
        return battle
    else: exit()
if __name__ == "__main__":
    battle()

我不知道你想调用哪种方法,但是我调用了battle()方法,它运行正常。

答案 1 :(得分:0)

首先将所有input更改为raw_input。另外我想我的想法是从intro函数开始,然后转到monsters函数,然后转到battle函数。虽然你已经定义好了,但你不要在任何地方调用它们。例如,您可以从monsters函数调用intro函数,然后从battle函数调用monsters函数