当尝试使用“+=”运算符时,不会添加到变量上

When trying to use the "+=" opperator, will not add on to the variable

我正在努力做到这一点,以便当用户或机器人赢得这一轮时,他们会得到一分,但在游戏结束时,当一个或另一个正确时,它似乎不会添加,我试过另一种方式 ('x = x + 1'),也请评价我的代码并告诉我我可以做得更好的地方。

import random

print('Lets play Rock Paper Scissors')

for tries in range (1,4):

    try:
        user_guess = input('Rock Paper Scissors? ')
        choices = ['Rock','Paper','Scissors']
        user_point = 0     #To keep track of the points 
        bot_point = 0     
        bot_guess  = random.choice(choices) #Will randomly pick from the list 'choices'

        while user_guess not in choices:#if the user tries to put in anything other then the choices given
            print('Please enter the choices above!')
            user_guess = input('Rock Paper Scissors? ')
    except ValueError:
        print('Please choose from the choices above ')  #Just in case user tries to put a different value type 
        user_guess = input('Rock Paper Scissors? ')

    DEBUG = "The bot did " + bot_guess

    print(DEBUG)

    if user_guess == bot_guess:
        print('Tie!')

    elif user_guess == "Rock" and bot_guess == "Paper":
        print('The bot earns a point!')
        bot_point += 1 

    elif user_guess == 'Paper' and bot_guess == "Rock":
        print('The user earns a point!')
        user_point += 1 

    elif user_guess == 'Paper' and  bot_guess == 'Scissors':
        print('The bot earns a point')
        bot_point += 1 

    elif user_guess == 'Scissors' and bot_guess == 'Paper':
        print('The user earns a point')
        user_point += 1 

    elif user_guess == 'Rock' and  bot_guess == 'Scissors':
        print('The user earns a point')
        user_point += 1 

    elif user_guess == 'Scissors' and bot_guess == 'Rock': 
        print('The bot earns a point')
        bot_point += 1




print('After ' + str(tries) + ' tries. ' + ' The score is')
print('The User: ' + str(user_point))
print('The Bot: ' + str(bot_point))

if user_point > bot_point:
    print('THE USER IS THE WINNER!!!')
else:
    print('THE BOT IS THE WINNER!!!')

您需要在开始 for 循环之前初始化 user_point 和 bot_point。就是这样,每次循环都将它们重置为零。