Python 我怎样才能得分?

Python 我怎样才能得分?,python,global,Python,Global,我试图让积分系统运行,但每当我运行时,它都会显示: UnboundLocalError : Local variable 'teambc' refrenced before assignment: 这是我的密码:- teambc = 0 teamac = 0 def bst_q(question, answer): rq = input(str(question)) if rq == answer: print ('Correct, Well done')

我试图让积分系统运行,但每当我运行时,它都会显示:

UnboundLocalError : Local variable 'teambc' refrenced before assignment:
这是我的密码:-

teambc = 0
teamac = 0
def bst_q(question, answer):

    rq = input(str(question))
    if rq == answer:
        print ('Correct, Well done')
        teambc += 1   
    elif rq != answer:
        print ('wrong. Team A now')
        rq = input(str(question))
        if rq == answer:
            print ('Correct, Well done')
            teamac += 1   
    elif rq != answer:
        print ('wrong. Both Wrong!')

bst_q('What is 13 times 2?','26')

这取决于你需要如何处理这两个变量。 以下是两个工作代码段,请选择您需要的一个:

def bst_q(question, answer):
  teambc = 0 
  teamac = 0
  rq = input(str(question))
  if rq == answer:
      print ('Correct, Well done')
      teambc += 1
  elif rq != answer:
      print ('wrong. Team A now')
      rq = input(str(question))
      if rq == answer:
          print ('Correct, Well done')
          teamac += 1
  elif rq != answer:
      print ('wrong. Both Wrong!')

bst_q("What's your name?","Luigi")

这取决于你需要如何处理这两个变量。 以下是两个工作代码段,请选择您需要的一个:

def bst_q(question, answer):
  teambc = 0 
  teamac = 0
  rq = input(str(question))
  if rq == answer:
      print ('Correct, Well done')
      teambc += 1
  elif rq != answer:
      print ('wrong. Team A now')
      rq = input(str(question))
      if rq == answer:
          print ('Correct, Well done')
          teamac += 1
  elif rq != answer:
      print ('wrong. Both Wrong!')

bst_q("What's your name?","Luigi")

您需要将
teamac
teambc
传递给函数,或在函数开头写入
global teambc
global teamac
,假设它们是全局变量。如果它们是全局变量,您需要将
teamac
teambc
传递给函数,或者在函数开头写入
global teambc
global teamac
。我已经编辑过了!现在应该可以了!它对我有用它也应该对你有用!我编辑过!现在应该可以了!它对我有用它也应该对你有用!