本文实例为大家分享了python实现石头剪刀布的具体代码,供大家参考,具体内容如下:
流程图:
代码如下:
importrandom
# define a function for get winner
# 1: Scissor
# 2: Stone
# 3: Cloth
defget_winner(you, me):
ifyou==me:
return0
ifyou==1:
ifme==2:
return-1
else:
return1
ifyou==2:
ifme==1:
return1
else:
return-1
ifyou==3:
ifme==2:
return1
else:
return-1
# define a function for get Label for finger
defget_lable(finger):
iffinger==1:
return"Scissor"
eliffinger==2:
return"Stone"
else:
return"Cloth"
you=raw_input("Your Finger is:")
whileint(you) >0:
you=int(you)%3
ifyou==0:
you=3
me=random.randint(1,3)
print"your finger is %s and my finger is %s"%(get_lable(you), get_lable(me))
result=get_winner(you, me)
ifresult==-1:
print"I Win."
elifresult==1:
print"You Win."
else:
print"No winner."
you=raw_input("Your Finger is:")
print"END"
以上就是“python实现剪刀石头布编程代码”的全部内容,想了解更多详情请持续关注编程学习网!
扫码二维码 获取免费视频学习资料
- 本文固定链接: http://phpxs.com/post/7949/
- 转载请注明:转载必须在正文中标注并保留原文链接
- 扫码: 扫上方二维码获取免费视频资料
查 看2022高级编程视频教程免费获取