python 小游戏,和电脑玩剪刀石头布

# -*- coding: utf-8 -*-
"""
Created on Fri Oct 25 16:28:12 2019
if判断综合演练,剪刀石头布
@author: fei
"""
import random
# 要使用随机数,需要导入随机数的模块random,--工具包

# 提示玩家出拳
player = int(input("请输入要出的拳:石头-1,剪刀-2,布-3"))

# randint(a, b)包含a和b,要求a<b
# 电脑随机出拳
computer = random.randint(1, 3)

print("玩家选择的拳头是:", player, ";电脑选择的拳头是:", computer)

# 比较胜负,石头胜剪刀,剪刀胜布,布胜石头
# 玩家胜利
if((player == 1 and computer == 2) 
        or (player == 2 and computer == 3) 
        or (player == 3 and computer == 1)):
    
    print("O yeah,电脑弱爆了!")
# 平局
elif player == computer:
    print("平局")
    
# 电脑胜利
else:
    print("电脑胜利,玩家失败!!!")
posted on 2019-10-25 18:32  行之间  阅读(1028)  评论(0编辑  收藏  举报