- 帖子
- 1
- 精华
- 0
- 积分
- 5
- 阅读权限
- 10
- 注册时间
- 2019-8-27
- 最后登录
- 2019-8-27
|
在自己编写crossin的点球小游戏中,我定义了我的函数,可是它没办法返回正确的bool值,求解答,为什么如图当我选择2,电脑也选择2时,我定义的函数的返回bool值应该是True,可是在输出时,判定为False,导致即使我的选择与电脑一样,输入我得分了?
代码如下:
def your(kick):
direction=["1","2","3"]
from random import choice
com=choice(direction)
print("you chosed %s"%kick)
print("com chosed %s"%com)
if kick==com:
return True
else:
return False
score_you=0
score_com=0
score1=False
for score in range(5):
print("Round%d,you kick!"%(score+1))
print("choose one direction to kick!")
print("1,2,3")
kick=input()
score1==your(kick)
if score1==False:
print("you socred!")
score_you=score_you+1
else:
print("com saved!")
score_com=score_com+1
print("Round%d,you save!"%(score+1))
print("choose one direction to save!")
print("1,2,3")
kick=input()
score1=your(kick)
if score1==True:
print("you saved!")
score_you=score_you+1
else:
print("com socred!")
score_com=score_com+1
print("your socre:%d"%score_you)
print("com's socre:%d"%score_com)
if score_you>score_com:
print("you win!")
else:
print("you lose!")
|
|