my cod上赋值错误前引用的局部变量

2024-06-28 16:19:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做的程序是一个骰子游戏,允许两个用户每人掷2个6面骰子。但我不确定如何正确地插入它,使分数变量成为全局变量,因为它不工作。玩家一的分数在变量p1score下,玩家二的分数存储在变量p2score下

def roundtwo():
    p1r2 = input("Player 1 are you ready for round 2 type y = yes n= no: ")
    if p1r2 == 'y' or p1r2 == 'Y':
        p1dice1 = random.randint(min,max)
        p1dice2 = random.randint(min,max)
        print("The value of dice 1 is:", p1dice1)
        print("The value of dice 2 is:", p1dice2)
        if (p1dice1 % 2) == 0 :
            p1score = p1score + p1dice1 + p1dice2
            p1score = p1score + 10
            print("The results for Player 1 in round 2 is: ", p1score)
        elif (p1dice2 % 2) == 0:
            p1score = p1score + p1dice1 + p1dice2
            p1score = p1score + 10
            print("The results for Player 1 in round 2 is: ", p1score)
        elif (p1dice1 % 2) == 0 and (p1dice2 % 2) == 0:
            p1score = p1score + p1dice1 + p1dice2
            p1score = p1score + 20
            print("The results for Player 1 in round 2 is: ", p1score)
        else:
            p1score = p1score + p1dice1 + p1dice2
            print("The results of Player 1 in round 2 is: ", p1score)
    else:
        user()

我需要它来计算两个玩家第二轮的分数。所以在第一轮之后,如果球员1得到3分,然后在第二轮得到14分,那么球员1在第一轮的得分应该是17分


Tags: oftheinforis玩家results分数