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("电脑胜利,玩家失败!!!")


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM