机器学习实战笔记_09_树回归_代码错误修正
1895
2022-08-18
Python实现石头剪刀布编程代码(python编写石头剪刀布)
本文实例为大家分享了python实现石头剪刀布的具体代码,供大家参考,具体内容如下:
流程图:
代码如下:
importrandom
# define a function for get winner
# 1: Scissor
# 2: Stone
# 3: Cloth
defget_winner(you, me):
ifyou==me:
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"
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~