Python 在创建时添加随机整数

Python 在创建时添加随机整数,python,random,Python,Random,我试图让计算机保存随机输出,然后添加它们 例如: ran_num = 1 ; ran_total = 1 ran_num = 3 ; ran_total = 4 等等 这一切都在while循环中 因此,在运行总数达到某个数字之前,它将继续添加这些数字 这是我试图修复的代码的一部分 if player_bet <= Player.total_money_amount: import random computer_choice = random.randint(1,

我试图让计算机保存随机输出,然后添加它们

例如:

ran_num = 1 ; ran_total = 1
ran_num = 3 ; ran_total = 4 
等等

这一切都在
while
循环中

因此,在运行总数达到某个数字之前,它将继续添加这些数字

这是我试图修复的代码的一部分

if player_bet <= Player.total_money_amount:

    import random

    computer_choice = random.randint(1, 5)
    computer_choice_total =+computer_choice # Over Here

    print('Computer choice: ', computer_choice)
    print("Total Amount", computer_choice_total)

    player_yes_or_no = input('Continue? Yes or No')
        if player_yes_or_no == 'Yes':

如果玩家下注您的问题最有可能出现在这一行(第5行):

=+
不是有效的Python运算符。相反,请使用
+=
,如下所示:

computer_choice_total += computer_choice

此外,您还需要确保Python代码正确缩进,否则它将无法按预期运行。

请您解释一下它是如何无法按预期工作的?您可能希望避免在该循环的每次迭代中导入“random”…+=并没有什么区别。它不会添加创建的随机整数。那只是为了证明我在做什么。我会再写一篇文章来澄清问题。无论如何谢谢你
computer_choice_total += computer_choice