#RoShamBo
import random
count=0
while count<2 and count> -2:
    compnum=random.randint(0,2)
    usernum=int(input("Scissor(0), Rock(1), Paper(2)"))
    if compnum==0:
        if usernum==0:
            print("Draw")
        elif usernum==1:
            print("Win")
            count=count+1
        elif usernum==2:
            print("Lose")
            count=count-1
    elif compnum==1:
        if usernum==0:
            print("Lose")
            count=count-1
        elif usernum==1:
            print("Draw")
        elif usernum==2:
            print("Win")
            count=count+1
    elif compnum==2:
        if usernum==0:
            print("Win")
            count=count+1
        elif usernum==1:
            print("Lose")
            count=count-1
        elif usernum==2:
            print("Draw")
if count>2:
    print("You won more than 2 times")
else:
    print("The computer won more than 2 times")


输出一团糟-一方面,它不会让用户获胜。另外,它没有正确计算数字。这是一门关于Python入门课程的实验作业,但我相信教授写的代码不正确。这是一个示例输出错误:

============== RESTART: C:/Users/FieryAssElsa/Desktop/Broken.py ==============
    Scissor(0), Rock(1), Paper(2)2
    Draw
    Scissor(0), Rock(1), Paper(2)2
    Win
    Scissor(0), Rock(1), Paper(2)2
    Draw
    Scissor(0), Rock(1), Paper(2)2
    Lose
    Scissor(0), Rock(1), Paper(2)2
    Win
    Scissor(0), Rock(1), Paper(2)2
    Win
    The computer won more than 2 times

最佳答案

您可以使用if count==2:尝试

关于python - 剪刀石头布不能让用户获胜,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39780248/

10-09 20:10