2013-09-28 2 views
2

저는 현재 python 3.3.2를 사용하고 있으며 텍스트 기반 게임을 만들고 있습니다. 공격 할 때 게임을 무작위로 고르려고합니다.Python은 목록에서 무작위로 선택하지 않습니다

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

그것은 왜 임의 따기에 도달하지 :이 실행할 때 내가 얻을 코드의 일부가

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

영향인가?

답변

0

두 번째 input()에 괄호가 없습니다. 줄 attack_spider = input은 단순히 함수를 실제로 호출하는 것이 아니라 새 함수에 입력 함수를 할당합니다. 또한 raw_input()을 사용하려고합니다. input()이 지정된 표현식을 평가하기 때문에 문자열을 원할 것입니다.

+0

마치 놓칠 수없는 것처럼 가능하게 만들 수 있습니까? "당신의 공격은 내 거미에게 화를냅니다. – dashernasher

관련 문제