首页 > 其他 > 详细

test_02分支_02_石剪刀布

时间:2019-05-12 11:26:03      阅读:128      评论:0      收藏:0      [点我收藏+]
# 导入random函数
import random
# 从控制台输入要出的拳 —— 石头(1)/剪刀(2)/布(3)
player = int(input("请输入您要出的拳 石头(1)/剪刀(2)/布(3)"))
# 电脑 随机 出拳 —— 先假定电脑只会出石头,完成整体代码功能
cumputer = random.randint(1,3)
print("玩家选择的拳头是 %d ,电脑出拳头是 %d 的" % (player, cumputer))
# 比较胜负
# 1 石头 胜 剪刀
# 2 剪刀 胜 布
# 3 布 胜 石头
if ((player==1 and cumputer==2)
or (player==2 and cumputer==3)
or (player==3 and cumputer==1)):

print("恭喜您胜出")
# 平局
elif player == cumputer :
print("心有灵犀,再来一局")
else :
print("很遗憾,您输了")

test_02分支_02_石剪刀布

原文:https://www.cnblogs.com/MagicApprentice/p/10851411.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!