我如何计算积分?

问题描述 投票:0回答:1

我试图让积分系统运行,但是每当我运行它时都说:

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')
python global tally
1个回答
0
投票

这取决于您需要使用这两个变量。这是两个工作代码段,请选择所需的代码段:

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")
© www.soinside.com 2019 - 2024. All rights reserved.