2

私は現在 python 3.3.2 を使用しており、テキスト ベースのゲームを作成しています。攻撃時にゲームにランダムに選択させようとしています。これは影響を受けるコードの一部です

        # North hand in hole
        if hand_in_hole == "Y":
           print ("Inside you brush aside cobwebs that must of not been moved in years. Sudenly somthing move against your skin. Do you remove your hand from the hole? Y/N")
           keep_handin_hole = input()
           #North/hand in hole/keep it in
           if keep_handin_hole == "N":
               print ("A huge spider as large as your fist crawls up your arm. Do you attack it? Y/N")
               attack_spider = input
               #North/hand in hole/keep it in/attack
               if attack_spider == "Y":
                   attack = ['Miss', 'Miss', 'Miss', 'Miss', 'Hit']
                   from random import choice
                   print (choice(attack))

これを実行すると、次のようになります。

    You must answer all questions in block capitals
    Welcome to maze runner are you ready Y/N?
    Y
    Chose your Name
    Callum
    Well hello Callum You find yourself in a deep dark maze you must escape before the beast      get's you. Are you still ready for the challange? Y/N
    Y
    You find yourself in the middle of the maze with four exits? NORTH/SOUTH/EAST/WEST
    NORTH
    There is a hole in the middle of the wall. Do you put your hand in? Y/N
    Y
    Inside you brush aside cobwebs that must of not been moved in years. Sudenly somthing move against your skin. Do you remove your hand from the hole? Y/N
    N
    A huge spider as large as your fist crawls up your arm. Do you attack it? Y/N
    >>> 

なぜランダムに選ぶことができないのですか?

4

1 に答える 1

0

2番目の括弧がありませんinput()。この行attack_spider = inputは、実際に関数を呼び出すのではなく、入力関数を新しい名前に割り当てるだけです。また、は指定された式を評価し、文字列だけが必要なraw_input()ため、おそらく を使用することをお勧めします。input()

于 2013-09-28T08:26:00.383 に答える