Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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
Python 尝试定义函数时出现错误消息_Python_Function - Fatal编程技术网

Python 尝试定义函数时出现错误消息

Python 尝试定义函数时出现错误消息,python,function,Python,Function,在repl.it上使用python 试图定义函数,并在试图运行程序时出现模糊语法错误。我试图通过重做压痕来解决这个问题,但运气不好。请帮忙。代码如下 health = 10 def labencounter(): entity = 'alchemist' battlevar = 0 entityhp = 10 print('An alchemist jumps out of the darkness, surrounded by neon ooze and bubbling v

在repl.it上使用python

试图定义函数,并在试图运行程序时出现模糊语法错误。我试图通过重做压痕来解决这个问题,但运气不好。请帮忙。代码如下

health = 10

def labencounter():
  entity = 'alchemist'
  battlevar = 0
  entityhp = 10
  print('An alchemist jumps out of the darkness, surrounded by neon ooze and bubbling vats!')
  battleaction = str(input('What will you do? [a]ttack [s]uper attack [i]tem or [r]un?'))
  while entityhp > 0:
    while battlevar  < 0:
      if battleaction == 'a':
        battlevar += 1
        entityhp -= 1
        health -= 3
        print('The ' + entity + '\'s health is' + entityhealth + '! Your health is ' + health)
        battlevar = 0
      elif battleaction == 's':
        battlevar += 1
        entityhp -= 3
        health -= 2
        print('The ' + entity + '\'s health is' + entityhealth + '! Your health is ' + health)
        battlevar = 0
      elif battleaction == 'i':
        battlevar += 1
        print('You have no items!')
        battlevar = 0
      elif battleaction == 'r':
        print('It chases you down and kills you.')
        health -= 10
      else:
        battleaction = str(input('[a]ttack [s]uper attack [i]tem or [r]un')


def entryway():
  x = 0
  enter = input('You see a gigantic doorway, yawning in the morning sun. Will you forsake the light and enter the dungeon? [y]/[n]')
  while x < 1:
    if enter.lower() != 'y' and enter != 'n':
      enter = input('[y]/[n]')
    elif enter.lower() == 'y':
      x += 1
      print('The darkness grows around you, as you yourself do the same into the abyss.')
    else:
      print('You turn away. Caves are not meant for one such as you.')
      exit()

我还没有关闭第31行的括号


battleaction=str(输入('a]ttack[s]uper attack[i]tem或[r]un'))

问题出在您未显示的部分代码中。可能是您忘记关闭前一行的括号…错误可能在于函数之前的内容。可能是标识、括号或某些未关闭的循环或其他内容。请编辑并添加前一行的内容,直到第34行
  File "main.py", line 34
    def entryway():
    ^
SyntaxError: invalid syntax