Python 石头、布、剪刀不';不要让用户赢
如果计数=2,您可以尝试使用Python 石头、布、剪刀不';不要让用户赢,python,while-loop,Python,While Loop,如果计数=2,您可以尝试使用,您能详细说明一下吗?您总是会看到计算机赢了2次以上,因为循环一直持续到计数为2或-2,然后达到条件。既然count是2或-2,并且2不大于2或-2,那么去else块解释一下就好了。但是我试着说“超过”2次。@FrostyElsacount>2永远不会是真的。我的头快要爆炸了。好的,你的意思是因为while循环设置了参数,计数不可能超过2。为了解决这个问题,如果我们将count设置为2(或者可能是3?),这将解决这个问题。 #RoShamBo import rando
,
您能详细说明一下吗?您总是会看到计算机赢了2次以上
,因为循环一直持续到计数
为2或-2,然后达到条件。既然count
是2或-2,并且2不大于2或-2,那么去else块解释一下就好了。但是我试着说“超过”2次。@FrostyElsacount>2
永远不会是真的。我的头快要爆炸了。好的,你的意思是因为while循环设置了参数,计数不可能超过2。为了解决这个问题,如果我们将count设置为2(或者可能是3?),这将解决这个问题。
#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")
============== 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