Python 石头剪刀布

#!usr/bin/python
# -*- coding:UTF-8 -*-
from __future__ import print_function
import uniout
import random
import time
while 1:
    s = int(random.randint(1,3))#s的值为1~3的随机数,random.randint()获取随机数的函数
    if (s == 1):
        ind = "石头"
    else:
        if (s == 2):
            ind = "剪刀"
        else:
            ind = "布"
    m = raw_input("请输入石头、剪刀、布,或输入end结束:")
    time.sleep(1)
    mlist = ['石头','剪刀','布']
    if (m not in mlist) and (m != 'end'):
        print("您的输入不正确,请重新输入!")
    else:
        if (m not in mlist) and (m == 'end'):
            print("\n游戏退出,谢谢!.")
            break
        else:
            if (m == mlist):
                print("电脑出了",ind,"平局")
            else:
                if (m == '剪刀' and ind == '布')or(m == '石头' and ind == '剪刀')or(m == '布' and ind == '石头'):
                    print("电脑出了",ind,"恭喜你,你赢了!")
                else:
                    if (m == '剪刀' and ind == '石头') or (m == '石头' and ind == '布') or (m == '布' and ind == '剪刀'):
                        print("电脑出了",ind,"很遗憾,你输了!")










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值