为什么我的代码没有超过某一行?

时间:2017-11-14 14:19:07

标签: python

每次运行我的代码时,只运行第二个布尔值,即使它应该测试所有选项然后运行那个选项。当我运行此代码时:

import random
Player_Score = 0
Computer_Score = 0
while Player_Score < 5 or Computer_Score < 5:
    Player_object = input("Would you like to choose R, P, or S?")
    Computer_object = random.sample(set(["R", "P", "S"]), 1)
    if Player_object == "R" or "r":
        if Computer_object == "R":
             print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have tied with the Computer and neither of you have scored a point.")
        elif Computer_object == "P":
            Computer_Score = Computer_Score + 1
            print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ". You have been beaten by the Computer and it has scored a point.")
        else:
            Player_Score == Player_Score + 1
            print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have beaten the Computer scored a point.")

我的结果如下:

You have chosen  R and the Computer chose ['S'].You have beaten the Computer scored a point.
Would you like to choose R, P, or S?R
You have chosen R and the Computer chose ['P'].You have beaten the Computer scored a point.
Would you like to choose R, P, or S?R
You have chosen R and the Computer chose ['S'].You have beaten the Computer scored a point.
Would you like to choose R, P, or S?R
You have chosen R and the Computer chose ['R'].You have beaten the Computer scored a point.
Would you like to choose R, P, or S?R
You have chosen R and the Computer chose ['P'].You have beaten the Computer scored a point.

有没有办法解决这个问题,因为在这一点上我不知道如何解决这个问题。

0 个答案:

没有答案