TypeError:“str”对象在中的第200行不可调用主.py

2024-09-24 02:21:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道我在说什么。也不知道一个字符串是怎么不能被调用的,它们是指变量还是什么?在

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

Tags: andthetoinputplayreturnifsleep
2条回答

您有一个名为play的变量

play = (input('Command:'))

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

如果您将play变量调用为其他值,则它不会与函数名play冲突。在

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

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

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

相关问题 更多 >