猜拳游戏 & 导入模块方法

猜拳游戏 & 导入模块方法

在这里插入图片描述

  • 解法
'''
0 石头  1 剪刀  2 布
1.玩家出拳
2.电脑出拳
3判断输赢
'''
player = int(input('0 石头  1 剪刀  2 布,玩家请出拳:'))
computer = 1
if (player == 0 & computer == 1) or (player == 1 & computer == 2) or (player == 2 & computer == 0):
    print('恭喜你获得胜利')
elif (player == 0 & computer == 0) or (player == 1 & computer == 1) or (player == 2 & computer == 2):
    print('平局')
elif (player == 0 & computer == 2) or (player == 1 & computer == 0) or (player == 2 & computer == 1):
    print('很遗憾你输了!!')
  • 导入随机数模块
    在这里插入图片描述
import random
"""
1.导入模块 import random
2.使用模块功能
3。random.randint()
"""

player = int(input('0 石头  1 剪刀  2 布,玩家请出拳:'))
computer = random.randint(0, 2)
if (player == 0 & computer == 1) or (player == 1 & computer == 2) or (player == 2 & computer == 0):
    print('恭喜你获得胜利')
elif (player == 0 & computer == 0) or (player == 1 & computer == 1) or (player == 2 & computer == 2):
    print('平局')
elif (player == 0 & computer == 2) or (player == 1 & computer == 0) or (player == 2 & computer == 1):
    print('很遗憾你输了!!')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值