Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Random Python没有从列表中随机选取_Random_Python 3.x - Fatal编程技术网

Random Python没有从列表中随机选取

Random Python没有从列表中随机选取,random,python-3.x,Random,Python 3.x,我目前使用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.

我目前使用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))
当我运行此命令时,我得到:

        # 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
    >>> 

它永远不会随机选择一个为什么?

第二个
input()
中缺少括号。行
attack\u spider=input
仅将输入函数分配给一个新名称,而不是实际调用该函数。另外,您可能希望使用
raw\u input()
,因为
input()
计算给定的表达式,而您只需要字符串。

是否可以使它成为可能,就像它等于未命中一样,说“您的攻击我的蜘蛛生气了?”
        # 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))