TypeError:' str' object在main.py中的第200行不可调用

时间:2017-05-16 13:22:27

标签: python string python-2.7 typeerror callable

解决

哦,好吧,错误。精彩。 这可能是一个非常容易解决的问题,但我不知道它在谈论什么字符串所以我有点卡住了。也不知道字符串如何无法调用,它们是指变量还是什么?

提前致谢。 (这是一个非常容易的问题,不是吗......)

from time import *

sleep(1)
axecount = 0

#intro

def fail():
  global rcommand
  rcommand = None
  sleep(1)
  print('---------------------------------------------')
  print('What? I did not understand, lol. Please time travel back to the past and retry.')
  sleep(1)
  print('')
  print('| RETURN |')
  print('---------------------------------------------')
  rcommand = input('Command:')
  if rcommand == 'RETURN':
    play()
  else:
    fail()
  print('---------------------------------------------')

def play():
  global axecount
  global rcommand
  rcommand = None
  print('---------------------------------------------')
  print('Welcome to...')
  print('')
  sleep(1)
  print('-=-=An Adventure through Time=-=-')
  print('')
  sleep(1)
  print('| PLAY | HELP | STORY |')
  print('')
  print('---------------------------------------------')
  sleep(1)
  play = (input('Command:'))
  print('---------------------------------------------')

  #if player chooses to play

  if play == 'PLAY':
    sleep(1)
    print('Well, let us begin!')
    print('')
    sleep(1)

    #map selection begins

    print('Select a map: DIMENSION, LANDMASS')
    print('---------------------------------------------')
    mapchooser = (input('Map chosen:'))

    #if player chooses the dimension map then...

    if mapchooser == 'DIMENSION':
      print('---------------------------------------------')
      print('Map DIMENSION loading...')
      print('---------------------------------------------')
      sleep(2)
      print('Loaded!')
      print('---------------------------------------------')
      sleep(1)
      print('-Stage 1-')
      print('---------------------------------------------')
      sleep(1)
      print('There are 3 doors. One at your LEFT, RIGHT, and FORWARD. Where do you go?')
      sleep(1)
      print('One of them has a monster... Good luck.')
      print('---------------------------------------------')

      #direction that he chooses to go at the first door choice

      def firstdoor():
        global axecount
        firstdoor = input('Command:')
        print('---------------------------------------------')

        #if player chooses to go left

        if firstdoor == 'LEFT':

          #dies

          sleep(1)
          print('Ouch! A monster! Travel back in time and retry!')
          print('---------------------------------------------')
        elif firstdoor == 'RIGHT':
          sleep(1)
          print('Wow, a chest has been found!')
          sleep(1)
          print('You get an axe!')
          print('Type INVENTORY as your command to view your items.')
          axecount += 1
          print('---------------------------------------------')

        elif firstdoor == 'INVENTORY':

          #opens inventory of player

          sleep(1)
          print('You have... ')
          print('Axes - ' + axecount)
          firstdoor()

      firstdoor()


    #if player chooses the landmass map then...

    elif mapchooser == 'LANDMASS':
      print('---------------------------------------------')
      print('Map LANDMASS loading...')
      sleep(3)
      print('Map LANDMASS not yet created. Coming soon!')
      print('Please time travel back to the past and retry.')
      sleep(1)
      print('| RETURN |')
      print('---------------------------------------------')
      rcommand = input('Command:')
      if rcommand == 'RETURN':
        play()
      else:
        fail()
      print('---------------------------------------------')

    #if player enters some nonsense that isnt correct

    else:
      sleep(1)
      print('---------------------------------------------')
      print('What? I did not understand, lol. Please time travel back to the past and retry.')
      sleep(1)
      print('')
      sleep(1)
      print('Look at HELP for more information.')
      print('---------------------------------------------')
      sleep(1)
      print('| RETURN |')
      print('---------------------------------------------')
      rcommand = input('Command:')
      if rcommand == 'RETURN':
        play()
      else:
        fail()
      print('---------------------------------------------')

  #help screenH

  elif play == 'HELP':
    sleep(1)
    print('Answer the command exactly how it looks like on the selection.')
    print('Example: Enter PLAY if it says PLAY')
    print('')
    sleep(1)
    print('There are monsters in some rooms and chests in some rooms.')
    print('Monsters kill you and the game ends.')
    print('Chests give you materials to try and kill the monster.')
    print('')
    sleep(1)
    print('Restart the game to go back to the selection screen.')
    sleep(1)
    print('---------------------------------------------')
    print('| RETURN |')
    print('---------------------------------------------')
    rcommand = input('Command:')
    if rcommand == 'RETURN':
      play()
    else:
      fail()


  elif play == 'STORY':
    sleep(1)
    print('You enter a dungeon but not all is what it seems...')
    sleep(1)
    print('The dungeon is haunted by powerful magic...')
    sleep(1)
    print('And each time you go to a room, the other rooms age by 10 years.')
    sleep(1)
    print('Is luck on your side?')
    sleep(1)
    print('---------------------------------------------')
    print('| RETURN |')
    print('---------------------------------------------')
    rcommand = input('Command:')
    if rcommand == 'RETURN':
      play()
    else:
      fail()
    print('---------------------------------------------')

  #if player enters some nonsense that isnt correct

  else:
    fail()

play()

(是的,这是我可怕的第一场比赛。)

2 个答案:

答案 0 :(得分:0)

你有一个名为play的变量,就在这里:

  sleep(1)
  play = (input('Command:'))
  print('---------------------------------------------')

此命名会干扰您的函数命名,将此变量名称更改为尚未用于函数的函数应该可以解决问题。

答案 1 :(得分:0)

您有一个名为play

的变量
play = (input('Command:'))

现在play是一个字符串,所以如果您尝试调用play(),它会尝试调用一个字符串,就像它是一个函数一样。

如果您将play变量称为其他内容,则不会与函数名play发生冲突。